开发者

How can I add styles to dynamically added table cells?

开发者 https://www.devze.com 2022-12-26 20:13 出处:网络
In my program I have a table that, when loaded, has jQuery add some styles/classes to the table cells and table headers.

In my program I have a table that, when loaded, has jQuery add some styles/classes to the table cells and table headers.

Everything works fine until rows are added via functionality on the rest of the page. Instead of adding the classes to the table cell during addition, is it possible to "listen" or fire some event that checks to see if child elements were added to the table.

Essentially, I want something functionally equivalent to this:

$(开发者_如何学运维"#table td").live("ready", function(){
 // do something
}); 

but the live/ready won't work on a table cell... Any ideas?


You can use a setInterval and then check for the dynamic addition of table cells, if you don't have access to other parts in the page.

setInterval(function(){
    CheckStyles();
}, 1000);

function CheckStyles()
{
    // your code goes here
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号