Reputation: 27740
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()); }
);
Upvotes: 1
Views: 2550
Reputation: 7430
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()
Upvotes: 1
Reputation: 322492
It is this
, but to use val()
you need a jQuery object.
$(this).val();
Upvotes: 2
Reputation: 28205
Try:
$("#txtFirstName,#txtLastName,#txtDOB").each(
function() { alert( $(this).val() ); }
);
Upvotes: 7