Reputation: 835
<table>
<tr>
<td><input id="txt1" type="text"></td>
<tr>
<tr>
<td><input id="txt2" type="text"></td>
<tr>
<tr>
<td><input id="txt3" type="text"></td>
<tr>
<tr>
<td><input id="txt4" type="text"></td>
<tr>
</table>
When i click on each text box, on a keyup event i should get id's of each textbox, what i should do.
Upvotes: 1
Views: 781
Reputation: 18600
$("table input").keyup(function(){
alert($(this).attr("id"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<table>
<tr>
<td><input id="txt1" type="text"></td>
<tr>
<tr>
<td><input id="txt2" type="text"></td>
<tr>
<tr>
<td><input id="txt3" type="text"></td>
<tr>
<tr>
<td><input id="txt4" type="text"></td>
<tr>
</table>
Upvotes: 1
Reputation: 133
$('input').keyup(function(){alert($(this).attr('id'))}
same thing for all textboxes
Upvotes: 1
Reputation: 85545
Use like this:
$('input').on('keypress',function(){//you may bind "keyup", "change", etc. event
console.log($(this).attr('id'));
});
Upvotes: 1