How to stop a class being added to an element if other elements have that class?












1















I have a slider that runs on a timer with buttons left and right that also move the slider.



The slider works by using JQuery to add an 'active' class to each 'li' element which in turn adds the correct CSS and animation.



The Problem:



When the sider is in animation and you click one of the buttons or you click the buttons repeatedly it doubles up the JQuery function adding class 'active' to more than one 'li' element so two or more images appear and mucks up the slider.



The Solution:



I want to put an if statement that says as long as no other 'li' elements have the 'active' class then run the function otherwise stop. As you can see I'm trying to use "if($("li:not(.active)")){" but this is not working. Any help greatly appreciated.



Here is my HTML(Twig):



    {% block stylesheets %}
<link rel="stylesheet" href="/theme/rbli-2017/css/carousel.css">
{% endblock stylesheets %}
{% setcontent slider = 'sliders/testslider' %}



<div id="slider">

<div class="control_prev">
<button class="prev_arrow">&lt;</button>
</div>

<ul class="slider-ul">
{% for slide in slider.feature %}

<div class="slide">

<li style="background-image: url({{slide.repeatimage|image}}); background-repeat: no-repeat;"
class="slider-li">
</li>

<div class="text-block">

<a href="{{slide.repeatimageLink}}" class="slider-link"> {{ slide.repeatimagetitle }} </a>

</div>

</div>
{% endfor %}
</ul>
<div class="control_next">
<button class="next_arrow">&gt;</button>
</div>

</div>



{% block my_javascripts %}

<script src="{{ paths.theme }}/js/carousel.js" type="text/javascript"></script>

{% endblock %}


Here is my JS(JQuery):



$(document).ready(function () {
$('.slide').first().addClass('active');
$('.active').css({"display": "block"});
setInterval(function () {

moveRight();

}, 4000);


});


function moveRight() {
console.log('moveRight()');


var currentSlide = $('.active');
var nextSlide = currentSlide.next('.slide');





function fadeOutOne() {
console.log('fadeOutOne()');
$('.slider-ul').removeAttr("style");
$('.next_arrow').removeAttr("style");

if($("li:not(.active)")){
$('.slide').first().fadeIn(300).delay('slow').addClass('active');
}


};

function fadeOutTwo() {
console.log('fadeOutTwo()');
$('.slider-ul').removeAttr("style");
$('.next_arrow').removeAttr("style");

if($("li:not(.active)")){
nextSlide.fadeIn(300).delay('slow').addClass('active');
}
};


if (nextSlide.length == 0) {


$('.slider-ul').animate({
marginLeft: '100px'
}, {
duration: 200,
queue: false
});
$('.slider-ul').animate({
marginRight: '-100px'
}, {
duration: 200,
queue: false
});
currentSlide.fadeOut(300).removeClass('active');
setTimeout(fadeOutOne, 500);


} else {



$('.slider-ul').animate({
marginLeft: '100px'
}, {
duration: 200,
queue: false
});
$('.slider-ul').animate({
marginRight: '-100px'
}, {
duration: 200,
queue: false
});
currentSlide.fadeOut(300).removeClass('active');
setTimeout(fadeOutTwo, 500);


}


};

function moveLeft() {
console.log('moveLeft()');
var currentSlide = $('.active');
var prevSlide = currentSlide.prev('.slide');



function fadeOutOne() {
console.log('fadeOutOne()');
$('.slider-ul').removeAttr("style");
$('.prev_arrow').removeAttr("style");

$('.slide').last().fadeIn(300).delay('slow').addClass('active');
};

function fadeOutTwo() {
console.log('fadeOutTwo()');
$('.slider-ul').removeAttr("style");
$('.prev_arrow').removeAttr("style");

prevSlide.fadeIn(300).delay('slow').addClass('active');
};



if (prevSlide.length == 0) {
$('.slider-ul').animate({
marginLeft: '-100px'
}, {
duration: 200,
queue: false
});
$('.slider-ul').animate({
marginRight: '100px'
}, {
duration: 200,
queue: false
});
currentSlide.fadeOut(300).removeClass('active');
setTimeout(fadeOutOne, 500);


} else {
$('.slider-ul').animate({
marginLeft: '-100px'
}, {
duration: 200,
queue: false
});
$('.slider-ul').animate({
marginRight: '100px'
}, {
duration: 200,
queue: false
});
currentSlide.fadeOut(300).removeClass('active');
setTimeout(fadeOutTwo, 500);


}
};

$('.next_arrow').click(function () {


moveRight();



});


$('.prev_arrow').click(function () {

function enableLeft(){
$('.prev_arrow').prop('disabled',false);
}

$('.prev_arrow').prop("disabled",true);
moveLeft();

setTimeout(enableLeft, 300);
});









share|improve this question



























    1















    I have a slider that runs on a timer with buttons left and right that also move the slider.



    The slider works by using JQuery to add an 'active' class to each 'li' element which in turn adds the correct CSS and animation.



    The Problem:



    When the sider is in animation and you click one of the buttons or you click the buttons repeatedly it doubles up the JQuery function adding class 'active' to more than one 'li' element so two or more images appear and mucks up the slider.



    The Solution:



    I want to put an if statement that says as long as no other 'li' elements have the 'active' class then run the function otherwise stop. As you can see I'm trying to use "if($("li:not(.active)")){" but this is not working. Any help greatly appreciated.



    Here is my HTML(Twig):



        {% block stylesheets %}
    <link rel="stylesheet" href="/theme/rbli-2017/css/carousel.css">
    {% endblock stylesheets %}
    {% setcontent slider = 'sliders/testslider' %}



    <div id="slider">

    <div class="control_prev">
    <button class="prev_arrow">&lt;</button>
    </div>

    <ul class="slider-ul">
    {% for slide in slider.feature %}

    <div class="slide">

    <li style="background-image: url({{slide.repeatimage|image}}); background-repeat: no-repeat;"
    class="slider-li">
    </li>

    <div class="text-block">

    <a href="{{slide.repeatimageLink}}" class="slider-link"> {{ slide.repeatimagetitle }} </a>

    </div>

    </div>
    {% endfor %}
    </ul>
    <div class="control_next">
    <button class="next_arrow">&gt;</button>
    </div>

    </div>



    {% block my_javascripts %}

    <script src="{{ paths.theme }}/js/carousel.js" type="text/javascript"></script>

    {% endblock %}


    Here is my JS(JQuery):



    $(document).ready(function () {
    $('.slide').first().addClass('active');
    $('.active').css({"display": "block"});
    setInterval(function () {

    moveRight();

    }, 4000);


    });


    function moveRight() {
    console.log('moveRight()');


    var currentSlide = $('.active');
    var nextSlide = currentSlide.next('.slide');





    function fadeOutOne() {
    console.log('fadeOutOne()');
    $('.slider-ul').removeAttr("style");
    $('.next_arrow').removeAttr("style");

    if($("li:not(.active)")){
    $('.slide').first().fadeIn(300).delay('slow').addClass('active');
    }


    };

    function fadeOutTwo() {
    console.log('fadeOutTwo()');
    $('.slider-ul').removeAttr("style");
    $('.next_arrow').removeAttr("style");

    if($("li:not(.active)")){
    nextSlide.fadeIn(300).delay('slow').addClass('active');
    }
    };


    if (nextSlide.length == 0) {


    $('.slider-ul').animate({
    marginLeft: '100px'
    }, {
    duration: 200,
    queue: false
    });
    $('.slider-ul').animate({
    marginRight: '-100px'
    }, {
    duration: 200,
    queue: false
    });
    currentSlide.fadeOut(300).removeClass('active');
    setTimeout(fadeOutOne, 500);


    } else {



    $('.slider-ul').animate({
    marginLeft: '100px'
    }, {
    duration: 200,
    queue: false
    });
    $('.slider-ul').animate({
    marginRight: '-100px'
    }, {
    duration: 200,
    queue: false
    });
    currentSlide.fadeOut(300).removeClass('active');
    setTimeout(fadeOutTwo, 500);


    }


    };

    function moveLeft() {
    console.log('moveLeft()');
    var currentSlide = $('.active');
    var prevSlide = currentSlide.prev('.slide');



    function fadeOutOne() {
    console.log('fadeOutOne()');
    $('.slider-ul').removeAttr("style");
    $('.prev_arrow').removeAttr("style");

    $('.slide').last().fadeIn(300).delay('slow').addClass('active');
    };

    function fadeOutTwo() {
    console.log('fadeOutTwo()');
    $('.slider-ul').removeAttr("style");
    $('.prev_arrow').removeAttr("style");

    prevSlide.fadeIn(300).delay('slow').addClass('active');
    };



    if (prevSlide.length == 0) {
    $('.slider-ul').animate({
    marginLeft: '-100px'
    }, {
    duration: 200,
    queue: false
    });
    $('.slider-ul').animate({
    marginRight: '100px'
    }, {
    duration: 200,
    queue: false
    });
    currentSlide.fadeOut(300).removeClass('active');
    setTimeout(fadeOutOne, 500);


    } else {
    $('.slider-ul').animate({
    marginLeft: '-100px'
    }, {
    duration: 200,
    queue: false
    });
    $('.slider-ul').animate({
    marginRight: '100px'
    }, {
    duration: 200,
    queue: false
    });
    currentSlide.fadeOut(300).removeClass('active');
    setTimeout(fadeOutTwo, 500);


    }
    };

    $('.next_arrow').click(function () {


    moveRight();



    });


    $('.prev_arrow').click(function () {

    function enableLeft(){
    $('.prev_arrow').prop('disabled',false);
    }

    $('.prev_arrow').prop("disabled",true);
    moveLeft();

    setTimeout(enableLeft, 300);
    });









    share|improve this question

























      1












      1








      1








      I have a slider that runs on a timer with buttons left and right that also move the slider.



      The slider works by using JQuery to add an 'active' class to each 'li' element which in turn adds the correct CSS and animation.



      The Problem:



      When the sider is in animation and you click one of the buttons or you click the buttons repeatedly it doubles up the JQuery function adding class 'active' to more than one 'li' element so two or more images appear and mucks up the slider.



      The Solution:



      I want to put an if statement that says as long as no other 'li' elements have the 'active' class then run the function otherwise stop. As you can see I'm trying to use "if($("li:not(.active)")){" but this is not working. Any help greatly appreciated.



      Here is my HTML(Twig):



          {% block stylesheets %}
      <link rel="stylesheet" href="/theme/rbli-2017/css/carousel.css">
      {% endblock stylesheets %}
      {% setcontent slider = 'sliders/testslider' %}



      <div id="slider">

      <div class="control_prev">
      <button class="prev_arrow">&lt;</button>
      </div>

      <ul class="slider-ul">
      {% for slide in slider.feature %}

      <div class="slide">

      <li style="background-image: url({{slide.repeatimage|image}}); background-repeat: no-repeat;"
      class="slider-li">
      </li>

      <div class="text-block">

      <a href="{{slide.repeatimageLink}}" class="slider-link"> {{ slide.repeatimagetitle }} </a>

      </div>

      </div>
      {% endfor %}
      </ul>
      <div class="control_next">
      <button class="next_arrow">&gt;</button>
      </div>

      </div>



      {% block my_javascripts %}

      <script src="{{ paths.theme }}/js/carousel.js" type="text/javascript"></script>

      {% endblock %}


      Here is my JS(JQuery):



      $(document).ready(function () {
      $('.slide').first().addClass('active');
      $('.active').css({"display": "block"});
      setInterval(function () {

      moveRight();

      }, 4000);


      });


      function moveRight() {
      console.log('moveRight()');


      var currentSlide = $('.active');
      var nextSlide = currentSlide.next('.slide');





      function fadeOutOne() {
      console.log('fadeOutOne()');
      $('.slider-ul').removeAttr("style");
      $('.next_arrow').removeAttr("style");

      if($("li:not(.active)")){
      $('.slide').first().fadeIn(300).delay('slow').addClass('active');
      }


      };

      function fadeOutTwo() {
      console.log('fadeOutTwo()');
      $('.slider-ul').removeAttr("style");
      $('.next_arrow').removeAttr("style");

      if($("li:not(.active)")){
      nextSlide.fadeIn(300).delay('slow').addClass('active');
      }
      };


      if (nextSlide.length == 0) {


      $('.slider-ul').animate({
      marginLeft: '100px'
      }, {
      duration: 200,
      queue: false
      });
      $('.slider-ul').animate({
      marginRight: '-100px'
      }, {
      duration: 200,
      queue: false
      });
      currentSlide.fadeOut(300).removeClass('active');
      setTimeout(fadeOutOne, 500);


      } else {



      $('.slider-ul').animate({
      marginLeft: '100px'
      }, {
      duration: 200,
      queue: false
      });
      $('.slider-ul').animate({
      marginRight: '-100px'
      }, {
      duration: 200,
      queue: false
      });
      currentSlide.fadeOut(300).removeClass('active');
      setTimeout(fadeOutTwo, 500);


      }


      };

      function moveLeft() {
      console.log('moveLeft()');
      var currentSlide = $('.active');
      var prevSlide = currentSlide.prev('.slide');



      function fadeOutOne() {
      console.log('fadeOutOne()');
      $('.slider-ul').removeAttr("style");
      $('.prev_arrow').removeAttr("style");

      $('.slide').last().fadeIn(300).delay('slow').addClass('active');
      };

      function fadeOutTwo() {
      console.log('fadeOutTwo()');
      $('.slider-ul').removeAttr("style");
      $('.prev_arrow').removeAttr("style");

      prevSlide.fadeIn(300).delay('slow').addClass('active');
      };



      if (prevSlide.length == 0) {
      $('.slider-ul').animate({
      marginLeft: '-100px'
      }, {
      duration: 200,
      queue: false
      });
      $('.slider-ul').animate({
      marginRight: '100px'
      }, {
      duration: 200,
      queue: false
      });
      currentSlide.fadeOut(300).removeClass('active');
      setTimeout(fadeOutOne, 500);


      } else {
      $('.slider-ul').animate({
      marginLeft: '-100px'
      }, {
      duration: 200,
      queue: false
      });
      $('.slider-ul').animate({
      marginRight: '100px'
      }, {
      duration: 200,
      queue: false
      });
      currentSlide.fadeOut(300).removeClass('active');
      setTimeout(fadeOutTwo, 500);


      }
      };

      $('.next_arrow').click(function () {


      moveRight();



      });


      $('.prev_arrow').click(function () {

      function enableLeft(){
      $('.prev_arrow').prop('disabled',false);
      }

      $('.prev_arrow').prop("disabled",true);
      moveLeft();

      setTimeout(enableLeft, 300);
      });









      share|improve this question














      I have a slider that runs on a timer with buttons left and right that also move the slider.



      The slider works by using JQuery to add an 'active' class to each 'li' element which in turn adds the correct CSS and animation.



      The Problem:



      When the sider is in animation and you click one of the buttons or you click the buttons repeatedly it doubles up the JQuery function adding class 'active' to more than one 'li' element so two or more images appear and mucks up the slider.



      The Solution:



      I want to put an if statement that says as long as no other 'li' elements have the 'active' class then run the function otherwise stop. As you can see I'm trying to use "if($("li:not(.active)")){" but this is not working. Any help greatly appreciated.



      Here is my HTML(Twig):



          {% block stylesheets %}
      <link rel="stylesheet" href="/theme/rbli-2017/css/carousel.css">
      {% endblock stylesheets %}
      {% setcontent slider = 'sliders/testslider' %}



      <div id="slider">

      <div class="control_prev">
      <button class="prev_arrow">&lt;</button>
      </div>

      <ul class="slider-ul">
      {% for slide in slider.feature %}

      <div class="slide">

      <li style="background-image: url({{slide.repeatimage|image}}); background-repeat: no-repeat;"
      class="slider-li">
      </li>

      <div class="text-block">

      <a href="{{slide.repeatimageLink}}" class="slider-link"> {{ slide.repeatimagetitle }} </a>

      </div>

      </div>
      {% endfor %}
      </ul>
      <div class="control_next">
      <button class="next_arrow">&gt;</button>
      </div>

      </div>



      {% block my_javascripts %}

      <script src="{{ paths.theme }}/js/carousel.js" type="text/javascript"></script>

      {% endblock %}


      Here is my JS(JQuery):



      $(document).ready(function () {
      $('.slide').first().addClass('active');
      $('.active').css({"display": "block"});
      setInterval(function () {

      moveRight();

      }, 4000);


      });


      function moveRight() {
      console.log('moveRight()');


      var currentSlide = $('.active');
      var nextSlide = currentSlide.next('.slide');





      function fadeOutOne() {
      console.log('fadeOutOne()');
      $('.slider-ul').removeAttr("style");
      $('.next_arrow').removeAttr("style");

      if($("li:not(.active)")){
      $('.slide').first().fadeIn(300).delay('slow').addClass('active');
      }


      };

      function fadeOutTwo() {
      console.log('fadeOutTwo()');
      $('.slider-ul').removeAttr("style");
      $('.next_arrow').removeAttr("style");

      if($("li:not(.active)")){
      nextSlide.fadeIn(300).delay('slow').addClass('active');
      }
      };


      if (nextSlide.length == 0) {


      $('.slider-ul').animate({
      marginLeft: '100px'
      }, {
      duration: 200,
      queue: false
      });
      $('.slider-ul').animate({
      marginRight: '-100px'
      }, {
      duration: 200,
      queue: false
      });
      currentSlide.fadeOut(300).removeClass('active');
      setTimeout(fadeOutOne, 500);


      } else {



      $('.slider-ul').animate({
      marginLeft: '100px'
      }, {
      duration: 200,
      queue: false
      });
      $('.slider-ul').animate({
      marginRight: '-100px'
      }, {
      duration: 200,
      queue: false
      });
      currentSlide.fadeOut(300).removeClass('active');
      setTimeout(fadeOutTwo, 500);


      }


      };

      function moveLeft() {
      console.log('moveLeft()');
      var currentSlide = $('.active');
      var prevSlide = currentSlide.prev('.slide');



      function fadeOutOne() {
      console.log('fadeOutOne()');
      $('.slider-ul').removeAttr("style");
      $('.prev_arrow').removeAttr("style");

      $('.slide').last().fadeIn(300).delay('slow').addClass('active');
      };

      function fadeOutTwo() {
      console.log('fadeOutTwo()');
      $('.slider-ul').removeAttr("style");
      $('.prev_arrow').removeAttr("style");

      prevSlide.fadeIn(300).delay('slow').addClass('active');
      };



      if (prevSlide.length == 0) {
      $('.slider-ul').animate({
      marginLeft: '-100px'
      }, {
      duration: 200,
      queue: false
      });
      $('.slider-ul').animate({
      marginRight: '100px'
      }, {
      duration: 200,
      queue: false
      });
      currentSlide.fadeOut(300).removeClass('active');
      setTimeout(fadeOutOne, 500);


      } else {
      $('.slider-ul').animate({
      marginLeft: '-100px'
      }, {
      duration: 200,
      queue: false
      });
      $('.slider-ul').animate({
      marginRight: '100px'
      }, {
      duration: 200,
      queue: false
      });
      currentSlide.fadeOut(300).removeClass('active');
      setTimeout(fadeOutTwo, 500);


      }
      };

      $('.next_arrow').click(function () {


      moveRight();



      });


      $('.prev_arrow').click(function () {

      function enableLeft(){
      $('.prev_arrow').prop('disabled',false);
      }

      $('.prev_arrow').prop("disabled",true);
      moveLeft();

      setTimeout(enableLeft, 300);
      });






      javascript jquery twig






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 27 '18 at 7:50









      danbdexdanbdex

      17110




      17110
























          1 Answer
          1






          active

          oldest

          votes


















          2














          if(!$('div.slide').hasClass('active')) { 
          $('div.slide:first').fadeIn(300).delay('slow').addClass('active');
          }





          share|improve this answer


























          • Tried this: if($("div").hasClass("active")){ return false; }else{ $('.slide').first().fadeIn(300).delay('slow').addClass('active'); } Not working still adding 'active' to more than one div on fast clicking.

            – danbdex
            Nov 27 '18 at 8:48











          • if(!$('div.slide').hasClass('active')) $('div.slide:first').fadeIn(300).delay('slow).addClass('active');

            – ygorbunkov
            Nov 27 '18 at 9:23













          • ..and, of course, that should be done within both moveRight() and moveLeft()

            – ygorbunkov
            Nov 27 '18 at 9:46











          • Hi, I've added this and it has now stopped the 'active' being added to more than one div. however the 'display:block' CSS is not taken off quick enough. So multiple images are still showing any ideas?

            – danbdex
            Nov 27 '18 at 10:23













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53494998%2fhow-to-stop-a-class-being-added-to-an-element-if-other-elements-have-that-class%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          if(!$('div.slide').hasClass('active')) { 
          $('div.slide:first').fadeIn(300).delay('slow').addClass('active');
          }





          share|improve this answer


























          • Tried this: if($("div").hasClass("active")){ return false; }else{ $('.slide').first().fadeIn(300).delay('slow').addClass('active'); } Not working still adding 'active' to more than one div on fast clicking.

            – danbdex
            Nov 27 '18 at 8:48











          • if(!$('div.slide').hasClass('active')) $('div.slide:first').fadeIn(300).delay('slow).addClass('active');

            – ygorbunkov
            Nov 27 '18 at 9:23













          • ..and, of course, that should be done within both moveRight() and moveLeft()

            – ygorbunkov
            Nov 27 '18 at 9:46











          • Hi, I've added this and it has now stopped the 'active' being added to more than one div. however the 'display:block' CSS is not taken off quick enough. So multiple images are still showing any ideas?

            – danbdex
            Nov 27 '18 at 10:23


















          2














          if(!$('div.slide').hasClass('active')) { 
          $('div.slide:first').fadeIn(300).delay('slow').addClass('active');
          }





          share|improve this answer


























          • Tried this: if($("div").hasClass("active")){ return false; }else{ $('.slide').first().fadeIn(300).delay('slow').addClass('active'); } Not working still adding 'active' to more than one div on fast clicking.

            – danbdex
            Nov 27 '18 at 8:48











          • if(!$('div.slide').hasClass('active')) $('div.slide:first').fadeIn(300).delay('slow).addClass('active');

            – ygorbunkov
            Nov 27 '18 at 9:23













          • ..and, of course, that should be done within both moveRight() and moveLeft()

            – ygorbunkov
            Nov 27 '18 at 9:46











          • Hi, I've added this and it has now stopped the 'active' being added to more than one div. however the 'display:block' CSS is not taken off quick enough. So multiple images are still showing any ideas?

            – danbdex
            Nov 27 '18 at 10:23
















          2












          2








          2







          if(!$('div.slide').hasClass('active')) { 
          $('div.slide:first').fadeIn(300).delay('slow').addClass('active');
          }





          share|improve this answer















          if(!$('div.slide').hasClass('active')) { 
          $('div.slide:first').fadeIn(300).delay('slow').addClass('active');
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 27 '18 at 11:08









          DarkBee

          9,20053044




          9,20053044










          answered Nov 27 '18 at 8:01









          ygorbunkovygorbunkov

          1,95311024




          1,95311024













          • Tried this: if($("div").hasClass("active")){ return false; }else{ $('.slide').first().fadeIn(300).delay('slow').addClass('active'); } Not working still adding 'active' to more than one div on fast clicking.

            – danbdex
            Nov 27 '18 at 8:48











          • if(!$('div.slide').hasClass('active')) $('div.slide:first').fadeIn(300).delay('slow).addClass('active');

            – ygorbunkov
            Nov 27 '18 at 9:23













          • ..and, of course, that should be done within both moveRight() and moveLeft()

            – ygorbunkov
            Nov 27 '18 at 9:46











          • Hi, I've added this and it has now stopped the 'active' being added to more than one div. however the 'display:block' CSS is not taken off quick enough. So multiple images are still showing any ideas?

            – danbdex
            Nov 27 '18 at 10:23





















          • Tried this: if($("div").hasClass("active")){ return false; }else{ $('.slide').first().fadeIn(300).delay('slow').addClass('active'); } Not working still adding 'active' to more than one div on fast clicking.

            – danbdex
            Nov 27 '18 at 8:48











          • if(!$('div.slide').hasClass('active')) $('div.slide:first').fadeIn(300).delay('slow).addClass('active');

            – ygorbunkov
            Nov 27 '18 at 9:23













          • ..and, of course, that should be done within both moveRight() and moveLeft()

            – ygorbunkov
            Nov 27 '18 at 9:46











          • Hi, I've added this and it has now stopped the 'active' being added to more than one div. however the 'display:block' CSS is not taken off quick enough. So multiple images are still showing any ideas?

            – danbdex
            Nov 27 '18 at 10:23



















          Tried this: if($("div").hasClass("active")){ return false; }else{ $('.slide').first().fadeIn(300).delay('slow').addClass('active'); } Not working still adding 'active' to more than one div on fast clicking.

          – danbdex
          Nov 27 '18 at 8:48





          Tried this: if($("div").hasClass("active")){ return false; }else{ $('.slide').first().fadeIn(300).delay('slow').addClass('active'); } Not working still adding 'active' to more than one div on fast clicking.

          – danbdex
          Nov 27 '18 at 8:48













          if(!$('div.slide').hasClass('active')) $('div.slide:first').fadeIn(300).delay('slow).addClass('active');

          – ygorbunkov
          Nov 27 '18 at 9:23







          if(!$('div.slide').hasClass('active')) $('div.slide:first').fadeIn(300).delay('slow).addClass('active');

          – ygorbunkov
          Nov 27 '18 at 9:23















          ..and, of course, that should be done within both moveRight() and moveLeft()

          – ygorbunkov
          Nov 27 '18 at 9:46





          ..and, of course, that should be done within both moveRight() and moveLeft()

          – ygorbunkov
          Nov 27 '18 at 9:46













          Hi, I've added this and it has now stopped the 'active' being added to more than one div. however the 'display:block' CSS is not taken off quick enough. So multiple images are still showing any ideas?

          – danbdex
          Nov 27 '18 at 10:23







          Hi, I've added this and it has now stopped the 'active' being added to more than one div. however the 'display:block' CSS is not taken off quick enough. So multiple images are still showing any ideas?

          – danbdex
          Nov 27 '18 at 10:23






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53494998%2fhow-to-stop-a-class-being-added-to-an-element-if-other-elements-have-that-class%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks