Gabin Andino Woods
Gabin Andino Woods

Reputation: 21

Javascript function .toggle start on hide?

i have this div
and this function

<div id="audio1" style='display:none; >
    $(document).ready(function() {
        $("#p1").on( "click", function() {
            $("#audio1").toggle(1500);

            });
    });

where do i need to put hide().

Upvotes: 0

Views: 112

Answers (2)

yousef
yousef

Reputation: 1372

hide() makes its style display equals to none

toggle switches between hide() and show() so if u want to hide and show use toggle other wise use hide

<html><head></head><body>

<p>Click the button to display a random number.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo" style="width:100px; height:100px; background-color:blue; display: block;"></p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
<script>

    function myFunction() {
        $('#demo').toggle();
    }
</script>



</body></html>

Upvotes: 2

Alperen Talaslıoğlu
Alperen Talaslıoğlu

Reputation: 31

I dont know an usage of display like this :

<div id="audio1" display="none" >

You should do like this :

<div id="audio1" style="display: none;" >

OR

$('#audio1').hide();

Upvotes: 1

Related Questions