Thursday, February 14, 2013

How to Get the Button ID On Button Click Event Using Jquery


HTML Code:

<input type="button" value="button"  id="btn"/>
Jquery Script:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('body').on('click', 'input[type=button]', function () {
alert(this.id); // <-- this refers to current clicked input button
});
});
</script>
Output:

No comments:
Write comments
Recommended Posts ×