Off the Ridge code

Off the Ridge Code Newsletter


jQuery – Pro Tip #3

Published January 24, 2015 in jQuery , ProTips - 1Comments

Extend jQuery pseudo class

It’s a little bit contrived example, but let’s say I have an input group:

     <div class=”form-group”>
        <input class=”form-control” type=”text” name=”name”>

and I’d like to do something to that input group, such as:


If I do it over and over again, I might consider wrapping it in a method:

function RemoveAddClass(selector){
    $( selector ).each(function() {

and this is pretty good, however there’s a better way, and that is extending jQuery pseudo class:

turning the above into:

$.extend($.expr[“:”], {
    removeAddClass: function(element){     

you can check out my fiddle here:

  • Visit here

    The formatting of your post is great. Easy to see, digest and share.