jQuery onClick capture the id of the element jQuery onClick capture the id of the element jquery jquery

jQuery onClick capture the id of the element


HTML:

<input type="radio" name="name" id="name" onchange="enableTxt(this)" /> 

JS:

function enableTxt(elem) {    var id = $(elem).attr("id");    alert(id);}


The html

 <button class="destroy" id="123">

The jQuery

  $('button.destroy').on('click', function(e){    e.preventDefault();    console.log(this.id);


You can pass just the ID from the HTML

<input type="radio" name="name" id="name" onchange="enableTxt($(this).attr('id'))" />function enableTxt(id){    alert(id);}