I am surprised that no one mentioned creating your own filter selector (an extension of the functionality of JQuery Selector). Here I created wildcard selectors, which I called "likeClass" and "likeId", which takes any wildcard and finds all the elements that match (similar to Regex matching).
The code:
$.expr[':'].likeClass = function(match){ return $('[class*=" '+ match +'"]'); }; $.expr[':'].likeId = function(match){ return $('[id*=" '+ match +'"]'); };
Usage example
Now suppose you have several div elements with similar names, such as .content-1, .content-2, .content-n ... etc., and you want to select them. Now it's a cake!
$ ('DIV: likeClass (content -)'); // Returns all elements that have the same class name: content - *
or
$ ('DIV: likeClass (content -)'); // Returns all elements with a similar identifier: content - *
Oh yes, one more thing ... you can hook it too. :)
$('li:likeId(slider-content-)').hide().addClass('sliderBlock').first().fadeIn('fast');
Enjoy it!
Timothy Perez May 30 '12 at 15:38 2012-05-30 15:38
source share