0

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().

2
  • Use hide method inside document ready to make the element hidden by default or use css display:none Commented Sep 20, 2015 at 21:09
  • Well, you must do $('#audio1").hide() initially. Commented Sep 20, 2015 at 21:10

2 Answers 2

2

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.