Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a HTML table dynamically. It displays the data well. Now I want to add an click event to select a row of this table. How can it be done dynamically? I can't find proper source code for it. If you know, could you share the info? Thanks.

What I have tried:

How to dynamically add a click event on a HTML table
Posted
Updated 6-Jul-16 0:05am
Comments
ZurdoDev 2-Jul-16 22:53pm    
Googling it will give you some results. I'm not sure the table can support the onclick event. You may have to attach it to all the tds. jQuery can make it very easy. Just google jquery table onclick.

1 solution

Please try this :

$('body').on('click', '<tabled_id>', function() {
    // do something
});
</tabled_id>


After forming the table in the DOM, call the above method and do the operation you need.

Ref :- javascript - In jQuery, how to attach events to dynamic html elements? - Stack Overflow[^]

Hope this will help you to find the solution :).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900