Harsha M V Harsha M V - 3 months ago 10
jQuery Question

jQuery onClick capture the id of the element

i have many input fields like this

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


when i click this radio button i wanna capture the id of the radio input. i am using the following code

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


Am getting this error

a.attributes is undefined

Answer

HTML:

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

JS:

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