i have a div element with id hover-1
, within the div i have a hidden form element having class name text_page_title
in the hierarchy.
i got the parent div element id dyanamically in a variable, now i want to find the hidden element having class name text_page_title
and set its value to 'foo'
structure is like:
<div id="hover-1">
<input type="hidden" class="text_page_title">
</div>
<div id="hover-2">
<input type="hidden" class="text_page_title">
</div>
I m trying to do it like:
$($parentId).find('input.text_page_title').val('foo');
but it doesnt work, m i missing something?
This works:
$("#hover-1").find('input.text_page_title').val('foo'); // or $("#hover-2")
If you want your parent id in a variable:
var parentId = $("#hover-1"); // or $("#hover-2");
parentId.find('input.text_page_title').val('foo');
working jsFiddle
Assuming that parentId
is the variable name containing the id string ("hover-1"), you should rewrite your quesry like this:
$('#'+parentId).find('input.text_page_title').val('foo');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With