I have following code (live: http://jsfiddle.net/xyZY8/1/):
var str = '<div>hello</div><ul><li>Some text...</li>' +
'<li>second item</li></ul>' +
'<input type="hidden" name="some_int" value="15" />';
var myVal = $(str).find("input[name=some_int]").val();
alert(myVal);
I want to get input hidden value. But this code does not work.
Any ideas ?
When you create new HTML using
$('<html string here>'), a new jQuery object will be created, containing all elements:Use
filter()if you want to select one of these childs.You can also wrap the HTML in a container, so that
find()can be used: