Wednesday, 15 January 2014

jquery - select second input on new dynamic added tablerow -



jquery - select second input on new dynamic added tablerow -

i'm having problem binding keyup delegated event on sec input in table html. want bind keyup event sec inputs in new table rows. possible?

<button id="mybutton">add new row</button> <table id="mytable"> <tr> <td>this static row.</td> <td><input type="text"> <td><input type="text"> </tr> </table> $("#mybutton").click(function () { var newrow = '<tr><td>dynamic row</td><td><input type="text"><td><input type="text"></tr>'; $('#mytable tr:last').after(newrow); }); $('#mytable').on('keyup', 'td input:eq(0)', function (event) { alert('keyup!!!!');

you want target sec input means need target td in sec input in case 3rd td of tr:

$('#mytable').on('keyup', 'tr td:eq(2) input', function (event) { alert('keyup!!!!');

if want skip first row not added dynamically then:

$('#mytable').on('keyup', 'tr:gt(0) td:eq(2) input', function (event) { alert('keyup!!!!');

jquery

No comments:

Post a Comment