javascript - Get id of clicked element using jquery -
this question has answer here:
- jquery: parent, parent id? 3 answers
i have series of select boxes within table. html is:
<td id="1"> <select id="a" name="xxx"> <option ... </option> </select> </td> <td id="2"> <select id="b" name="yyy"> <option ... </option> </select> </td> ... etc.
when select box option changed, how can use jquery return id of select box , td?
i think should like:
$(document).ready(function() { $('select').change(function() { var id = $(this).attr('id'); return false; }); });
working fiddle
you can use on function change event , find td using closest
$(document).ready(function() { $('select').on('change',function() { var id = $(this).attr('id'); var tdid = $(this).closest('td').attr('id'); return false; }); });
Comments
Post a Comment