Posted By

quickredfox on 09/04/09


class jquery repalce

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite



 / Published in: jQuery

I notice a lot of addClass/removeClass.. thought maybe I'd post an example on how to simplify that....

  1. /*
  2. ** jquery.replaceClass.js -- jQuery "plugin", helps classname manip.
  3. ** Copyright (c) 2007 Francois Lafortune (
  4. ** Licensed under MIT
  5. **
  6. */
  7. jQuery.fn.replaceClass = function(toReplace,replaceWith){
  8. return $(this).each(function(){
  9. return $(this).removeClass(toReplace).addClass(replaceWith);
  10. });
  11. }
  13. // Of course, you'd rarely ever save this file like this, what you wanna do
  14. // is create a little extensions file for all your tiny little jQuery
  15. // quirks and re-use that...
  16. jQuery.extend(jQuery.fn,{
  17. replaceClass = function(){//code...},
  18. otherHelper = function(){ //... }
  19. // etc ...
  20. })

Report this snippet  


RSS Icon Subscribe to comments
Posted By: joe-bbb on September 28, 2009

Thats nice, however shouldn't that be a colon not an equals? e.g.

//jQuery extension object jQuery.extend(jQuery.fn,{ replaceClass : function(toReplace,replaceWith){ return $(this).each(function(){ return $(this).removeClass(toReplace).addClass(replaceWith); }); } })

//call $('#first-col').click(function(){ $(this).replaceClass('person','dog'); });

Posted By: jordansair002 on October 7, 2010

The Air Jordan shoes Michael Jackson Edition is inspired by the Cheap Jordans. There are multiple designs, which can be viewed our Nike jordan website. This has for being the a single issue the ultimate MJ admirer is lacking in research of the total outfit, unless they program on obtaining Air Yeezy to launch some specific edition socks Air Yeezy shoes too.

Posted By: jordansair002 on October 7, 2010

The Moncler Jackets outletcome in totally different styles and features. The Cheap moncler jackets are available with hoods too which reflect a casual put on Moncler Online. In addition, the very simple collection belonging to the inexpensive Moncler outlet can also be offered that is ideal for any casual day.Winter is coming, Moncler shop possibly some men and women stated that it is not possible to search fashionable, simply because we are normally in heavy and thick Moncler sale.

You need to login to post a comment.