开发者

find element and set the value

开发者 https://www.devze.com 2023-04-02 19:16 出处:网络
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 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');
0

精彩评论

暂无评论...
验证码 换一张
取 消