views:

31

answers:

3

how do i get a reference to the element that matched? 'this' is not correct.

For example here I am trying to alert with the elements value.

//how do i get this to reference the object it matches.
$("#txtFirstName,#txtLastName,#txtDOB").each(
    function() { alert(this.val()); }
);
+3  A: 

Try:

$("#txtFirstName,#txtLastName,#txtDOB").each(
    function() { alert( $(this).val() ); }
);
inkedmn
+1  A: 

It is this, but to use val() you need a jQuery object.

$(this).val();
patrick dw
A: 

In that context this is a reference to the actual DOM element. You will need to wrap that into a jQuery object in order to use the val() function.

$(this).val()
Naeem Sarfraz