jQuery Toggle +/-

Status
Not open for further replies.

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,484
1,485
I actually have this working on my own site, but trying to get it to work on here as a user script :p
I'm just now starting to work with jQuery, so sorry if this is something easy.
Code:
    $('li.node').each(function() {
        $(this).click(function(){
            $(this).toggleClass("open");
            $(this).find('li').toggle(300);
        });
        if ($(this).hasClass("open")) {
            $('.toggle-icon').html("<i class='fa fa-minus-circle'></i>");
        } else {
            $('.toggle-icon').html("<i class='fa fa-plus-circle'></i>");
        }
    });
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,484
1,485
I'm making the forum categories toggle, and I'm trying to get the + / - to change depending on if the category is open or not.



Like that.

The categories toggle, the + just doesn't change to a -
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
ooohh i forget how to do this, but I had it on my sidebar I made a thread and someone helped before. Try to find it maybe? I have to go to work so I don't have time to look but there's already a thread with the answer to this kinda help!
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,484
1,485
I figured this out about five minutes posting this
Code:
    $('li.node').each(function(event){
       $(this).click(function() {
           $(this).toggleClass("open");
           $(this).find('li').toggle(300);
           if ($(this).hasClass("open")) {
            $('.toggle-icon',this).html("<i class='fa fa-minus-circle'></i>");
        } else {
            $('.toggle-icon',this).html("<i class='fa fa-plus-circle'></i>");
        }
       });
    });
 
Status
Not open for further replies.

Users who are viewing this thread

Top