jquery - Getting index of clicked row that's dynamically created -


i've created table 3 rows can expanded use of add button. want know index of every row click. have piece of code works fine on 3 automatically generated rows, not on rows add using add button.

here's fiddle shows issue: http://jsfiddle.net/4wa5kfpz/, actual code has lot more stuff in basic/stripped version.

as can see, rows added between first 2 , last not respond when clicked. i've tried (see below, based on this question) add click event table rows, didn't work.

$("table tr").on('click', '#mytable tr', function(e){     alert('clicked row '+ ($(this).index()+1) ); }); 

any ideas?

use .on event:

$("#mytable").on('click', 'tr', function(){       alert('clicked row '+ ($(this).index()+1) ); }); 

http://jsfiddle.net/4wa5kfpz/1/


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -