Reputation: 15477
I have a table with an image on each row with a hover event attached. Can someone please show me how to alert the value of the hidden field?
<div class='first'>
<input type="hidden" value="target">
<div class='second'>
<img src="yada" />
</div>
</div>
thanks, rodchar
Upvotes: 0
Views: 371
Reputation: 3954
Give the hidden field an id:
<input id="hidden_yada" type="hidden" value="target">
And get the value directly:
$("#hidden_yada").attr('value');
Upvotes: 2
Reputation: 17750
For this specific case, you could do :
$("img[src='yada']").parent().prev().attr('value');
To get the value.
But, it's not a good practice. This code will easily break when you change your HTML structure.
Upvotes: 0
Reputation:
You can find the image tag object in your event handler, then get the parentNode and traverse the DOM tree to get the value.
Upvotes: 0