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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:40:33+00:00 2026-05-26T20:40:33+00:00

Using $(#myTable tr).live(click, someCallback); (although now deprecated) it is fairly simple to subscribe to

  • 0

Using $("#myTable tr").live("click", someCallback); (although now deprecated) it is fairly simple to subscribe to the click event for newly added table rows.

I would be interested in a way which doesn’t only support events but any jQuery commands, something like:

$("myTable tr").live().attr("hello", "world");

which would add the hello=”world” attribute to any newly added table rows. Is there any such thing in jQuery?

Update: Please note. I want to subscribe to the event of an element being added. I do not control the code which adds it. Take dataTables as a example: The dataTables plug-in creates the table rows.

  • 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-26T20:40:34+00:00Added an answer on May 26, 2026 at 8:40 pm

    I would say there are two reasons why this doesn’t really exist.

    1. DOM modification events are not widely supported. You could listen for DOMSubtreeModified in Chrome and FF, but not in IE and Opera.
    2. Checking every DOM event against a selector would be very costly. .live/.delegate is already pretty inefficient of a strategy.

    To help picture 2, imagine that 1 isn’t a problem and we can capture any time an element is added to the DOM. When this happens, we need to evaluate the new element and its children against "#myTable tr". This will significantly increase the amount of non-native code executing with every DOM change in scope, really slowing things down.

    The best strategy is to add your desired jQuery changes to the code that would be inserting the <tr>

    UPDATE If you have no choice and only have to support Chrome and FF, there is one solution I can think of. Obviously, it will not be fast and you can improve your performance through specificity:

    $.fn.elementInserted = function(pattern, fn) {
        return this.bind('DOMNodeInserted', function(event) {
                if (event.target.nodeType != 1) return;
                $(event.target).filter(pattern).each(fn);
        });
    };
    
    /* SLOW */ $(document).elementInserted('#myTable tr', function(){$(this).attr('hello', 'world');});
    /* FASTER */ $('#myTable').elementInserted('tr', function(){$(this).attr('hello', 'world');});
    

    See an example here: http://jsfiddle.net/vCZHQ/

    You could theoretically check if the table has changed in IE by doing a timeout:

    var oldEls = $('#myTable tr');
    setInterval(function() {
        var newEls = $('#myTable tr');
        if(oldEls.length < newEls.length) {
            /* Do code here to figure out who is new and apply changes. */
        }
        oldEls = newEls;
    }, 50);
    

    That said, this will have a slight delay and really drain a laptop’s battery.

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

Sidebar

Related Questions

$('a.loadTable').live('click', function(event) { $('#myTable').html(); // loop over elements to load table: $('#myTable').append(<tr><td> + item.id
I am using a simple query in ActiveRecord which does something like this. MyTable.find(:all,
Currently I am using $('#mytable tr').click(function() { blah blah }); This makes all rows,
I have a table called Mytable in home/models.py and using django aep I reference
I'm using a simple mysql LIKE query like this: SELECT * FROM myTable WHERE
Let's say I create a random table MyTable using a SQL statement (CREATE TABLE
Using SQLite3, if you create a table like this: CREATE TABLE MyTable ( id
I have an SQLite database with a virtual table myTable created using FTS4, with
Using the following simple code: $aQuery = INSERT into myTable (a, b, c) VALUES
Using Access 2003 In my table column, some of the fields are null, some

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.