Find all elements on a page whose element ID contains a certain text using jQuery

user48408 picture user48408 · Jul 30, 2009 · Viewed 191.7k times · Source

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.

Answer

karim79 picture karim79 · Jul 30, 2009
$('*[id*=mytext]:visible').each(function() {
    $(this).doStuff();
});

Note the asterisk '*' at the beginning of the selector matches all elements.

See the Attribute Contains Selectors, as well as the :visible and :hidden selectors.