I'm a nub in jQuery and javascript in general, so this must be a beginners question.
This line works for me, foo is not empty:
var foo = $("#hello").find("option").filter (function(){return $(this).text() == "BAR";});
This one in the same spot doesn't (foo undefined):
var foo = $("#hello").find("option").filter (function(){return $(this).attr("innerText") == "BAR";});
The only difference is using .text() vs .attr("innerText"). Why the latter doesn't work for me?
innerText
? Also, does#hello
without quotes in your selector really work? And the quotes areBAR
are not the same quotes.innerText
is a property, you'd get that with jQuery'sprop()
method, but why would you when you can usetext()
instead, which is cross browser (innerText is not)