0

Is it possible to do an if statement so that this script only runs if the first div is != #MyCustomID1 div.fixedClass?

jQuery(document).ready(function($) {
    $("#MyCustomID2 div.fixedClass").click(function(){
        $(this).toggleClass("active");
        $(this).next("MyCustomClass2 div.fixedClass").stop('true','true').slideToggle(600);
    });
});

I'm wanting to run the same script doing the same thing in two separate plugins, but I don't want them to conflict. Or maybe it's possible to name the functions and have one check for the other before it proceeds?

4

1 回答 1

0

Not elegant, but it works. In one plugin, I'll add classes first, then get those classes when I call the toggle transition. Like this:

jQuery("#myCustomID h3.fixedClass").addClass("sseo-metaslide");
jQuery("#myCustomID div.fixedClass").addClass("sseo-metaslide-child");
    jQuery(document).ready(function($) {
        $("h3.sseo-metaslide").click(function(){
            $(this).toggleClass("active");
            $(this).next("div.sseo-metaslide-child").stop('true','true').slideToggle(600);
        });
    });

Then in the other plugin, I'll start by removing those classes that I added in the first plugin, then just call the toggle transition by the fixed classes, like this:

jQuery("#myCustomID h3.fixedClass").removeClass("sseo-metaslide");
jQuery("#myCustomID div.fixedClass").removeClass("sseo-metaslide-child");
    jQuery(document).ready(function($) {
        $("h3.fixedClass").click(function(){
            $(this).toggleClass("active");
            $(this).next("div.fixedClass").stop('true','true').slideToggle(600);
        });
    });

This way, the first plugin's toggle transition doesn't get stuck in an open/close loop, if both plugins are activated.

于 2013-10-05T22:14:39.483 回答