html - how to show id of a button using Jquery? -


here demo of code. want show id of button while saying undefined

demo.

code:

$('#btn').on('click', function () {     var $this = $(this);     var id = $(this).id;     alert(id);  }); 

simply use dom native functions , properties:

$('#btn').on('click', function () {     alert(this.id);     }); 

if decided want use jquery overkill:

alert($(this).attr('id'));     

Comments