lundi 20 novembre 2017

if 'this case' and 'that case' do 'something' else do 'other something'

I'm trying to create an onClick function which only works below resolution of 768px. The function works on other resolutions such as 992px and above, but for some reason the function still works on resolution 768px itself.

following is my code:

$(document).on('click','.active-tab', function(e){
  if ($(window).width() < 768) {
    if($(this).hasClass('active')) {
      $(this).removeClass("active");
      $(this).siblings().slideUp("fast");
    } else {
      $(this).addClass('active');
      $(this).parent().find('li').slideDown("fast");
    }
  }
  e.preventDefault();
});

Is it the syntax where I am mistaken? or perhaps I'm forgetting something? Appreciate the help guys, thanks.

Aucun commentaire:

Enregistrer un commentaire