Getting the ID of the element that fired an event using jQuery

来源:互联网 发布:java装饰模式好处 编辑:程序博客网 时间:2024/05/21 09:02

Getting the ID of the element that fired an event using jQuery



7down vote

I generate a table dynamically out a database, receive the data in JSON and put it into a table. Every table row got a unique ID, which is needed for further actions, so, if the DOM is altered you need a different approach:

$("table").delegate("tr", "click", function() {   var id=$(this).attr('id');   alert("ID:"+id);  });
share|improve this answer

7down vote

I generate a table dynamically out a database, receive the data in JSON and put it into a table. Every table row got a unique ID, which is needed for further actions, so, if the DOM is altered you need a different approach:

$("table").delegate("tr", "click", function() {   var id=$(this).attr('id');   alert("ID:"+id);  });
share|improve this answer
原创粉丝点击