Hiding a div by default

前端 未结 7 1149
半阙折子戏
半阙折子戏 2021-01-01 10:28

I have a div that should be shown only when the user clicks the show button

$(\"div.toshow\").show();

I have written in the body

         


        
相关标签:
7条回答
  • 2021-01-01 11:32

    You can use either Display or Visibility

    display:none|block|etc.. // This will not preserve the space for the div.
    visibility:visible|hidden //This will preserve the space for the div but wont be shown.
    

    If you use display your $("div.toshow").show(); will cause your element to jump up as the space wasn't preserved for it. That will not happen with Visibility.

    One way to do this is have your dispay assigned to the class

    .toshow
    {
      display:none;
    }
    

    in your script:-

    $("div.toshow").show();
    

    Or Just provide:-

    <div class="toshow" style="display:none;">...
    
     $("div.toshow").show();
    

    When you do a .show() jquery just adds display:block inline style to your markup.

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