Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1087515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:56:56+00:00 2026-05-16T22:56:56+00:00

I have table which class is forum . My jquery code: <script type=text/javascript> $(document).ready(function()

  • 0

I have table which class is forum. My jquery code:

<script type="text/javascript">
    $(document).ready(function() {
        $('.forum').bind("mouseover", function(){
            var color  = $(this).css("background-color");

            $(this).css("background", "#380606");

            $(this).bind("mouseout", function(){
                $(this).css("background", color);
            })    
        })    
    })
</script>

It perfectly works, but is it possible to do it in more efficient way without var color = $(this).css("background-color");. Just after mouseout leave the previous background-color and remove #380606? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:56:57+00:00Added an answer on May 16, 2026 at 10:56 pm

    If you don’t care about IE ≤6, you could use pure CSS …

    .forum:hover { background-color: #380606; }
    
    .forum { color: white; }
    .forum:hover { background-color: #380606 !important; }
    /* we use !important here to override specificity. see http://stackoverflow.com/q/5805040/ */
    
    #blue { background-color: blue; }
    <meta charset=utf-8>
    
    <p class="forum" style="background-color:red;">Red</p>
    <p class="forum" style="background:green;">Green</p>
    <p class="forum" id="blue">Blue</p>

    With jQuery, usually it is better to create a specific class for this style:

    .forum_hover { background-color: #380606; }
    

    and then apply the class on mouseover, and remove it on mouseout.

    $('.forum').hover(function(){$(this).toggleClass('forum_hover');});
    
    $(document).ready(function(){
      $('.forum').hover(function(){$(this).toggleClass('forum_hover');});
    });
    .forum_hover { background-color: #380606 !important; }
    
    .forum { color: white; }
    #blue { background-color: blue; }
    <meta charset=utf-8>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <p class="forum" style="background-color:red;">Red</p>
    <p class="forum" style="background:green;">Green</p>
    <p class="forum" id="blue">Blue</p>

    If you must not modify the class, you could save the original background color in .data():

      $('.forum').data('bgcolor', '#380606').hover(function(){
        var $this = $(this);
        var newBgc = $this.data('bgcolor');
        $this.data('bgcolor', $this.css('background-color')).css('background-color', newBgc);
      });
    
    $(document).ready(function(){
      $('.forum').data('bgcolor', '#380606').hover(function(){
        var $this = $(this);
        var newBgc = $this.data('bgcolor');
        $this.data('bgcolor', $this.css('background-color')).css('background-color', newBgc);
      });
    });
    .forum { color: white; }
    #blue { background-color: blue; }
    <meta charset=utf-8>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <p class="forum" style="background-color:red;">Red</p>
    <p class="forum" style="background:green;">Green</p>
    <p class="forum" id="blue">Blue</p>

    or

      $('.forum').hover(
        function(){
          var $this = $(this);
          $this.data('bgcolor', $this.css('background-color')).css('background-color', '#380606');
        },
        function(){
          var $this = $(this);
          $this.css('background-color', $this.data('bgcolor'));
        }
      );   
    
    $(document).ready(function(){
      $('.forum').hover(
        function(){
          var $this = $(this);
          $this.data('bgcolor', $this.css('background-color')).css('background-color', '#380606');
        },
        function(){
          var $this = $(this);
          $this.css('background-color', $this.data('bgcolor'));
        }
      );    
    });
    .forum { color: white; }
    #blue { background-color: blue; }
    <meta charset=utf-8>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <p class="forum" style="background-color:red;">Red</p>
    <p class="forum" style="background:green;">Green</p>
    <p class="forum" id="blue">Blue</p>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a table in MySQL which represents a base class, and I
In a SQL server database, I have a table which contains a TEXT field
I'm trying to use an input validation script in jquery. Which executes on document
I have a Jquery function which opens a <a> tag to a division (similar
I have a CSS class called grid which I place on my tables. I
I have a table which is full of arbitrarily formatted phone numbers, like this
I have a table which is referenced by foreign keys on many other tables.
I have a table which contains my server status create table ServerStatus ( ServerId
I have a table which defines a child-parent relationship between nodes: CREATE TABLE node
I have a table which holds flight schedule data. Every schedule have an effective_from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.