I have a string being passed to jquery like this
“”
I want to get the value of the bar attribute from the input.
I have
var htmlstring = "<input id='foo' type='checkbox' bar='foobar'/><img id='blah' src='blahblah' />";
var bar = $(htmlString).find('input:checkbox').attr("bar");
but it doesnt seem to be working?
Any ideas?
THANKS!
Change
.find()to.filter().Example: http://jsfiddle.net/2QkRm/
This is because the
find()[docs] method only looks at descendants of the elements at the top level of the jQuery object, whereas thefilter()[docs] method looks only at the top level elements.Also, this may be a typo in the question, but your capitalization changed on your
htmlStringvariable.