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 6325971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:59:40+00:00 2026-05-24T16:59:40+00:00

Hope my title is not too confusing. Please let me know if there is

  • 0

Hope my title is not too confusing. Please let me know if there is a better way to title my problem.
I have jQuery function applying background-color to the odd rows in a table and on hover change the color to red. But if I edit the table dynamically my jQuery does not work any more.

I read a lot about JS event delegation and could not find any information about how to make this work without having actual event…

$(document).ready(function(){
    //add background-color to all odd rows
    //very important!!!
    $("#tab3 tbody tr:odd").css("background-color", "#DCF1FD");
    //change color on hover 
    //less important!!!     
    $("#tab3 tbody tr").hover(
      function () {
        $(this).css("color", "red");
      },
      function () {
        $(this).css("color", "#000");
      }
    );
});

Is there a way to make it work after I edit the table.

EDIT:
This must work on IE8

  • 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-24T16:59:41+00:00Added an answer on May 24, 2026 at 4:59 pm

    use jQuery delegate on the table that will work even if you update the table rows dynamically because the event is attached to table and not each rows of it.

    $(document).ready(function(){
        $("#tab3 tbody tr:odd").css("background-color", "#DCF1FD");
    
    
        $("#tab3").delegate('tbody tr', 'hover', function(){
            $(this).css("color", "red");
          },
          function () {
            $(this).css("color", "#000");
        });
    });
    

    If you are updating the whole table dynamically then use this

    $(document).delegate('#tab3 tbody tr', 'hover', function(){
            $(this).css("color", "red");
          },
          function () {
            $(this).css("color", "#000");
     });
    

    You can set the background color of odd row with simple css

    #tab3 tbody tr:nth-child(odd)
    { 
       background: #DCF1FD; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope the title is not too confusing. I am trying to make folders
I hope the title doesn't sound too subjective; I absolutely do not mean to
I'm not even sure about how to title this qn. But, hope there is
I hope the title did not mislead you. My problem is the following: Currently
I hope the title and following text are clear, I'm not very familiar with
I hope the title makes sense. I have a set of items that I
(I hope my title is comprehensible, it was hard to sum up.) I have
I hope my title is not misleading, but what I'm looking for is a
OK the question title is vague, but here's the problem. I have a list
Forgive me if the title is not lucid, but I could not better describe

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.