plugging in custom selector in jquery


A line on code speaks for 1000 lines of  explanation 🙂 .. so here it is

jQuery.extend(jQuery.expr[‘:’], {
classStartsWith: function(a, i, m){
var classes = $(a).attr(“className”).split(” “)
var found = false;
for (var i = 0; i < classes.length; i++) { if (classes[i].startsWith(m[3])) { found = true; break; } } return found; } }); [/sourcecode] The above code plugs in a custom selector for matching all the elements which have class starting with a certain string so [sourcecode language='javascript'] $('input:classStartsWith('highlight')') [/sourcecode] a selector like above would select all the input elements with class starting with highlight . I guess the code is pretty straight forward so I'm not going to go exegetic on the code .


No Responses Yet to “plugging in custom selector in jquery”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: