How do I hide an HTML element before the page loads using jQuery

前端 未结 7 1332
独厮守ぢ
独厮守ぢ 2020-12-07 20:44

I have some JQuery code that shows or hides a div.

$(\"div#extraControls\").show();   // OR .hide()

I initially want the div to be not visi

7条回答
  •  情话喂你
    2020-12-07 21:33

    With CSS3 you can actually hide content until a page loads by taking advantage of the :only-child selector.

    Here is a demonstration of how to do this. The basic idea is that CSS while loading will add a single node to the DOM while loading that node and its child nodes. Further, once a second child is added to the given parent node the :only-child selector rule is broken. We match against this selector and set display: none to hide the given node.

    
    
    
    
      
        Hide content until loaded with CSS
        
      
    
      
        

    Content Hidden

提交回复
热议问题