Wouldn't it be better to toggle between the first and the second  
class, rather than limiting it to replacing the first with the second?

$.fn.swapClass = function(c1, c2) {
     return this.each(function() {
        var $this = $(this);
        if ( $this.hasClass(c1) )
                $this.removeClass(c1).addClass(c2);
        else if ( $this.hasClass(c2) )
                $this.removeClass(c2).addClass(c1);
     });
};

This one favors c2: if an element has both c1 and c2, it keeps c2 the  
first time it's called. Otherwise, it acts as advertised.

--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Nov 1, 2008, at 12:09 PM, Buguletzu wrote:

>
> replaceClass would be like:
>
> replaceClass ( oldClass, newClass )
> Returns: jQuery
> Replaces the first class with the second class.
>
> My code for this is:
> jQuery.fn.extend({
>       'replaceClass': function(remC,addC){
>               return this.each(function() { $
> (this).removeClass(remC).addClass(addC); });
>       }
> });
>
> I would hope this gets implemented by default in jQuery.
> Cheers.
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to