Toggle between two classes in jQuery Toggle between two classes in jQuery jquery jquery

Toggle between two classes in jQuery


How about

$(YOUR_ELEMENT).live("EVENT_NAME", function() {    $(".portlet-header").toggleClass("ui-icon-plus").toggleClass("ui-icon-minus");});

Even more shorter

$(YOUR_ELEMENT).live("EVENT_NAME", function() {    $(".portlet-header").toggleClass("ui-icon-plus ui-icon-minus");});

EDIT

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.Users of older versions of jQuery should use .delegate() in preference to .live().


jQuery API reference


You can try the below code

$(this).toggleClass('ui-icon-plusthick ui-icon-minusthick');


It probably because when you bind those functions there are no results for $(".portlet-header .ui-icon-plusthick"). It doesn't find it. You may add this binding to $(".portlet-header .ui-icon-minusthick").click(function() { ... after adding "ui-icon-plusthick" class.

EDIT:Alternative solution could be:

$(".portlet-header .ui-icon-minusthick").toggle(function() {        $(this).removeClass("ui-icon-minusthick");        $(this).addClass("ui-icon-plusthick");        $(this).parents(".portlet:first").find(".portlet-content").toggle();    }, function() {        $(this).removeClass("ui-icon-plusthick");        $(this).addClass("ui-icon-minusthick");        $(this).parents(".portlet:first").find(".portlet-content").toggle();    });

So first click would be first function and second click would be second function.