Harsha M V Harsha M V - 1 year ago 79
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");

Am getting this error

a.attributes is undefined

Answer Source


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


function enableTxt(elem) {
    var id = $(elem).attr("id");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download