hide div when page load

前端 未结 3 891
情深已故
情深已故 2021-01-18 05:28

I have jquery issue, Kindly see my jquery code:

$(document).ready(function(){

    $(\".toggle_container\").show();

    $(\"h2.trigger\").toggle(function(){         


        
相关标签:
3条回答
  • 2021-01-18 05:38

    Once the document gets loaded, a alert box will be prompted "page loaded".

    $(document).ready(function(){    
        alert('page loaded');  // alert to confirm the page is loaded    
        $('.divClassName').hide(); //enter the class or id of the particular html element which you wish to hide. 
    });
    
    0 讨论(0)
  • 2021-01-18 05:46

    You can just add attribute

    style="display:none"
    

    to your element .toggle_container.

    Then on first call of $(document).ready it will be shown.

    The full test example:

    <html>
    <head>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
      <script type="text/javascript">
        $(document).ready(function(){
          $("h2.trigger").click(function(){
            $(this).next(".toggle_container").slideToggle("slow,");
          });
        });
      </script>
    </head>
    <body>
      <h2 class="trigger">Toggle</h2>
      <div class="toggle_container" style="display:none">Container</div>
    </body>
    </html>
    

    Note: there`s no $(".toggle_container").show(); on $(document).ready

    0 讨论(0)
  • 2021-01-18 06:05

    remove the

    $(".toggle_container").show();
    

    from your $(document).ready function.

    in html part add style="display:none" for the toggle_container div.

    check the @HCK s reply. he is clearly mentioned it..

    0 讨论(0)
提交回复
热议问题