user3356666
user3356666

Reputation: 39

Check if toggle true addClass else if not removeClass

(Thank you guys ... I have fix it)

Please I need your help if you can

I want when the toggle are show ... addClass "activeee" and remove it from other div's and when the toggle are hide removeClass

My problem is : when I click on the toggle to hide it (toggle hide) it's have been hide but the Class don't remove this is my jquery code

jQuery(document).ready(function($){


    $("#mashmenu-mod-1").click(function(){
         $(".mod-content").fadeOut();
        var mod1 = $(this).find(".mod-content").toggle();
        mod1;
        var Checkmod1 = $(this).find(".mod-content").data("toggled", "true"); 

        if(Checkmod1) {
            $("#mashmenu-mod-1").addClass("activeee");
        } else {
            $("#mashmenu-mod-1").removeClass("activeee");
        }
    });

    $("#mashmenu-mod-2").click(function(){
        $(".mod-content").fadeOut();
        $(this).find(".mod-content").toggle();
    });


    $("#mashmenu-mod-3").click(function(){
        $(".mod-content").fadeOut();
        $(this).find(".mod-content").toggle();
    });

});

Upvotes: 1

Views: 317

Answers (2)

Ali Elzoheiry
Ali Elzoheiry

Reputation: 1682

var Checkmod1 = $("#mashmenu-mod-1").data("toggled", "true");

The above line of code will always set toggled to true, it will never enter the else, therefore never removing the class

Upvotes: 2

tinabaninaboo
tinabaninaboo

Reputation: 54

I think you are trying to set Checkmod1 to be true if #mashmenu-mod-1 is toggled, but data("toggled", "true") does not return the current state of the toggled attribute - it creates and sets an attribute "toggled" to the string "true". See data() documentation here.

Instead, check the state using the following:

var Checkmod1 = $("#mashmenu-mod-1").is(":hidden"); 

Upvotes: 1

Related Questions