Jquery Hide an Element Right Away


/ Published in: jQuery
Save to your folder(s)

Handy. Hide an element as soon as possible, before document.ready. The element gets hidden but only when a class is applied to the html via js.


Copy this code and paste it in your HTML
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <script type="text/javascript" src="../assets/js/jquery.js"></script>
  6.  
  7. <script type="text/javascript">
  8.  
  9. $(function () {
  10. $('html').addClass('no-message');
  11. });
  12. </script>
  13. </head>
  14. <body>
  15. <style type="text/css">
  16. html.no-message .box {display:none;}
  17. </style>
  18. <p>In other news...</p>
  19. <div class="box"><p>I shoud be hidden!</p></div>
  20. </body>
  21. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.