Skip to content Skip to sidebar Skip to footer

Hide Div When Page Load

I have jquery issue, Kindly see my jquery code: $(document).ready(function(){ $('.toggle_container').show(); $('h2.trigger').toggle(function(){ $(this).addCla

Solution 1:

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

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

Solution 2:

remove the

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

from your $(document).ready function.

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

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

Solution 3:

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. 
});

Post a Comment for "Hide Div When Page Load"