How does the reverse function work in jQuery?

1

I created this code and am trying to do the inverse function, ie if it is closed, it opens, if it is open date. I'm having problems and I can not 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");

});
    
asked by anonymous 16.11.2014 / 16:01

1 answer

5

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

 $(".formsEditProdutos").toggleClass("esconde");
    
16.11.2014 / 19:33