How does the inverse function work in jQuery?

Asked

Viewed 60 times

1

I created this code and I’m trying to do the reverse function, IE, if it’s closed, open, if it’s open close. I’m having problems and I don’t see anything on the console. Can you help me?

/////////////////////////////////////////////
$("#edit_prod").on("click", function(event) {
    event.preventDefault();

    ////////////////////////////////
    var code = $(this).data("forms");
    $(".formsEditProdutos").addClass("esconde");
    $(".formsEditProdutos").attr("id", code).removeClass("esconde");

}, function(event){

    var code = $(this).data("forms");
    $(".formsEditProdutos").attr("id", code).addClass("esconde");

});
  • 4

    The click does not accept two functions. I see that you are changing the ID every click, it seems strange, I think there are better ways to do that... You can explain what you want to do?

  • You can put the HTML of this #edit_prod and of .formsEditProdutos? Then I can give you a suggestion as to how best to do it.

1 answer

5

Try to use the method toggleClass. Using it, if the class is present, it removes, and if not present, it adds.

 $(".formsEditProdutos").toggleClass("esconde");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.