views:

2434

answers:

4

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:

http://docs.jquery.com/Selectors/hidden

http://docs.jquery.com/Selectors/visible

karim79
+1  A: 

This selects all DIVs with an ID containing 'foo' and that are visible

$("div:visible[id*='foo']");
port-zero
If im searching for textbox elements rather than divs, is it simply $("input:visible[id*='foo']"); ?
it would be $("input[type='textbox'][id*='foo']:visible")
karim79
@port-zero - the single quotes around 'foo' are not necessary
karim79
+1  A: 

Thanks to both of you. This worked perfectly for me.

$("input[type='text'][id*=" + strID + "]:visible").each(function() {
    this.value=strVal;
});
A: 

thank u both it perfectly i'm looking for too..thanks a lot