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

  • SEARCH
  • Home
  • 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 1017183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:39:53+00:00 2026-05-16T10:39:53+00:00

I have this code somewhere in my plugin: $(‘tr’, $this).hover(function(){ var cur_color = null;

  • 0

I have this code somewhere in my plugin:

$('tr', $this).hover(function(){
  var cur_color = null;
  cur_color = $this.css('background-color');
$this.css('background-color', options.tr_hover_bgcolor);
}, function(){
  $this.css('background-color', cur_color);
});

Above, $this refers to wrapped set or table as an example. The code is supposed to change the rows background color on mouse enter and mouse leave. It does not work when used inside the plugin. Outside the plugin the similar code just works fine. Also that is the only part of the code not working in the plugin, rest of the things are working fine.

This code works which is not a plugin:

$('#' + table_id + ' tr').hover(function(){
  cur_color = $(this).css('background-color');
  $(this).css('background-color', '#FFF3B3');
}, function(){
  $(this).css('background-color', cur_color);
});

Can you please point out why above code doesn’t work in the plugin?

Thanks

  • 1 1 Answer
  • 3 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-16T10:39:53+00:00Added an answer on May 16, 2026 at 10:39 am

    This part:

    $('tr', $this).hover(function(){
      var cur_color = null;
      cur_color = $this.css('background-color');
      $this.css('background-color', options.tr_hover_bgcolor);
    }, function(){
      $this.css('background-color', cur_color);
    });
    

    Should be something like this:

    $('tr', $this).hover(function() {
      $.data(this, 'bgColor', $(this).css('background-color'));
      $(this).css('background-color', options.tr_hover_bgcolor);
    }, function() {
      $(this).css('background-color', $.data(this, 'bgColor'));
    });
    

    So you’re changing the background of the hovered row, instead of the whole table. The version that works is currently relying on a global variable…where as the plugin version was out of scope. This approach instead stores it per-row using $.data().


    Unless you need to support IE6 though (or need this to be dynamic), you can do something like this in CSS:

    .hoverTable tr:hover { background-color: #EEEEEE; }
    

    Not sure if it’s an option, just something to be aware of.


    Also, take a look at the .delegate() way, which is much faster to bind if you have many rows:

    $($this).delegate('tr', 'mouseeneter', function() {
       $.data(this, 'bgColor', $(this).css('background-color'));
       $(this).css('background-color', options.tr_hover_bgcolor);
    }).delegate('tr', 'mouseleave', function() {
       $(this).css('background-color', $.data(this, 'bgColor'));
    });
    

    This attaches a single handler to each table, instead of each row in each table, and listens for the events to bubble. If you have many rows, this is much faster to bind, resulting in better page load time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: $(div[id^='intCell']).mouseover(function() { $(this).css({ border:,1px solid #ff097c}); }).mouseout(function() { $(this).css({border:,1px solid
you must have seen this piece of code somewhere else too,but obviously there's no
I have this Objective-C code that I found somewhere. Honestly, I don't understand a
Basically, I have somewhere in my main code where this line of code is
I have this code for doing an ajax request to a webservice: var MyCode
I have this code somewhere in my controller: raise PermissionDenied When this is executed,
I think many of you have this kind of code somewhere: int foo; switch
I saw this code somewhere without the PHP backend for it and have wondering
I have this code to show a map using the Virtual Earth API: <script
I have this code here, which is intended to allow any type of arguments:

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.