hasClassLike allows the selection of elements based on pattern matching rather than specific names. This allows, for example, the passing of parameters to JavaScript via class names:
/* in js, such as in $(document).ready */ $("*") .hasClassLike("integer") /* filter some before using regexp */ .hasClassLike(/^integer(?:Min(-?\d+))?(?:Max(-?\d+))?$/,function(m) { var min = m[1]; var max = m[2]; // ... install validating event handlers on $(this) ... });
<!-- in HTML --> <input type="text" class="someOtherClass integerMin0"/> <input type="text" class="integerMin-100Max100 someOtherClass"/> <input type="text" class="someOtherClass integer yetAnotherClass"/>
There is an efficient simple substring match .hasClassLike(str) matched against the entire className of the element (that is, the space-separated list), useful for paring out unlikely elements. Then, a RegExp match with .hasClassLike(rx) comes back with the elements bearing at least one class matching a given pattern. Adding a callback function with .hasClassLike(rx,fn) makes it easy to modify or filter the found elements based on the match, which is passed to the callback function. If the callback returns false, the element is not included in the output (like with .filter).