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">
开发者_JAVA百科<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 $parentId is the parent Id:
$('#'+$parentId).find('input.text_page_title:hidden').val('foo');
You will be sure to get only hidden input
Use this code :
$("#hover-1").find(".text_page_title").val('foo');
精彩评论