Problem clicking the button, called ajax

0

Code:

<button id="click" class="button"></button>
    <div class="TableCSS">
        <table id="clickvent">
        </table>
    </div>

   $(document).ready(function(){
            $("#click").click(function(){
                if($("#clickvent").is(":visible")){
                        $("#clickvent").hide();
                    } else{
                        $("#clickvent").show();
                    }                   
                $.ajax({
                    url: "../Conteudo/click.html",
                    cache: false,
                    dataType: 'html'
                })
                .done(function(retorno) {
                    $("#clickvent").html(retorno);
                })
                .fail(function() {
                    alert("Algo está errado");
                });
            });
        });

You're calling it all right, but when I click the button you need to double-click to load the contents of the click.html page. Does anyone know the error? And just by squeezing for the first time it happens to have to double-click, to hide the content it's all normal just to load that happens.

    
asked by anonymous 11.04.2016 / 19:11

1 answer

1

You have to click 2 times to appear because when the page loads the condition if($("#clickvent").is(":visible")) already gives true then it executes the hide() to only in the next click appear. Suggestion for solution is before the execution of the click event of the button add the following line:

$("#clickvent").hide();

Another solution would be to add in CSS as follows:

#clickvent {
   display: none;
}
    
11.04.2016 / 21:18