Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery hide show div doesn't work in Internet Explorer

When I click togglediv, commentdiv must be visible or hidden. The following code is running on Firefox but not Internet Explorer:

$(document).ready(function(){
    $("#togglediv").click(function(){ 
        if( $("#commentdiv").is(":visible") ) {
            $("#commentdiv").hide("slow");
            $("#togglediv").text("show");
        } else {
            $("#commentdiv").show("slow");
            $("#togglediv").text("hide");
        }
    });
});
like image 441
ferixxx Avatar asked Dec 07 '22 08:12

ferixxx


1 Answers

There is a function toggle in jquery that does exactly what you want without having to check for visibility:

$("#commentdiv").toggle("slow");
like image 132
jeroen Avatar answered Jan 09 '23 04:01

jeroen