I'm trying to find all elements on a page whose element ID contains a certain text. I'll then need to filter the found elements based on whether they are hidden or not. Any help is greatly appreciated.
+5
A:
$('*[id*=mytext]:visible').each(function() {
$(this).doStuff();
});
Note the asterisk '*' at the beginning of the selector matches all elements.
See attributeContains:
http://docs.jquery.com/Selectors/attributeContains#attributevalue
Also see the :hidden and :visible filters:
karim79
2009-07-30 13:51:41
+1
A:
This selects all DIVs with an ID containing 'foo' and that are visible
$("div:visible[id*='foo']");
port-zero
2009-07-30 13:57:24
If im searching for textbox elements rather than divs, is it simply $("input:visible[id*='foo']"); ?
2009-07-30 13:58:39
it would be $("input[type='textbox'][id*='foo']:visible")
karim79
2009-07-30 14:00:16
@port-zero - the single quotes around 'foo' are not necessary
karim79
2009-07-30 14:00:51