lundi 20 avril 2020

How do I make my JQuery .on('click', ) work more than once?

I'm trying to create a sliding pop-up, where you can click on a label to slide and reveal the content, and then click again on the same label to hide the content. I'm using JQuery to animate the div class, but the animation only gets triggered by the click once. I tested, and both of the functions do work, but once it's triggered the one way, it wont trigger again. Here's the JavaScript, the functions are nested in an if statement:

$(document).ready(function(){
    var listSlide = $(".tutor-list").css("top");
    (listSlide === "0px")? $(document).on('click', '#list-slide', function(){
            $(".tutor-list").animate({top: "200px"});
        }) : $(document).on('click', '#list-slide', function(){
            $(".tutor-list").animate({top: "0px"});
        }); 
}); 

I'm very new to Javascript, so it is possible that the issue lies in a syntax error or some fundamental flaw, but I can't find what's wrong with it.

Aucun commentaire:

Enregistrer un commentaire