[jQuery] Enabling wildcards in .className selector
I recently had a need for a simple wildcard in the class selector syntax.
eg: $("INPUT.myClass*") would match .myClass1 and .myClassHello etc.
As an experiment to make this work I made a small change to JQuery's code
but that is decidedly poor practice! I'd like to apply the change as a small
plugin but the section of code in question is quite long and I presume the
plugin would have to include all of it in order to replace the existing code
on the fly.
So...
- Is there an easier way to apply this small change as a plugin?
- My mod is shown below. It changes regex syntax that looks for matches in
className, the same regex appears more than once in the code so my solution
is by no means complete - it just suited my needs. A more efficient fix
would be change them all, perhaps have them generated and returned by a
small function
- Don't go thinking I suggest everyone should start modifying their copy of
the jquery code! It's just an experiment!
The code-line in question is half way through the source under the comment
"// Pre-compile a regular expression to handle class searches":
- Change from: var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
- to: var rec = new RegExp("(^|\\s)" + m[2].replace('*','[a-zA-Z0-9_-]*') +
"(\\s|$)");
Cheers,
George
--
View this message in context: http://www.nabble.com/Enabling-wildcards-in-.className-selector-tf3220488.html#a8943907
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/