var selector = "ul.lower-menu li a[innerText=\"" + PanelSettings[tab_name_key] + "\"]";
I’m trying to get horizontal menu tab that has innerText property set to the previously stored value.
The config value is stored like this:
PanelSettings[tab_name_key] = $("ul.lower-menu li:first > a").prop("innerText");
It is actually there and it always has the proper value.
I get nothing from jQuery – am I doing something obviously wrong here?
Edit: I’m using jQuery 1.6.4
Yes, you are doing something wrong. The attribute selector selects elements that have a certain attribute set.
innerTextis a property, not an attribute – as indeed you recognise by usingpropto set it.You have two options. One is to use the
:containsselector:This, however, would select
foobarif you asked forfoo. The better option is to do the filtering yourself, usingfilter:This selects only the elements whose text content is the same as the setting given.
NB also, as Diodeus says, you should use
text()rather thanprop('innerText').