Toggle between two classes in jQuery

后端 未结 5 1478
一向
一向 2020-12-05 07:06

I\'m trying to modify the icons for the jQuery UI portlets. Rather than have a plus to minimize and a minus to expand, I wanted to switch them.

I\'ve only had lim

5条回答
  •  一向
    一向 (楼主)
    2020-12-05 07:44

    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.

提交回复
热议问题