code_junkie

Can I target an element before it's closed?

Nov 11th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <body>
  2. $("body").addClass("active");
  3. ...
  4. </body>
  5.  
  6. <body>
  7. <div id='topStories'></div>
  8. <script type='text/javascript'>
  9. $('div#topStories').addClass('active');
  10. </script>
  11. </body>
  12.  
  13. <html>
  14. <head>
  15. <style type="text/css">
  16. .foobar { background-color: #CCC; }
  17. </style>
  18. </head>
  19. <body>
  20. <script type="text/javascript">
  21. window.document.body.className = "foobar";
  22. </script>
  23. <div style="border: solid 1px"><br /></div>
  24. <script type="text/javascript">
  25. // happens before DOM is fully loaded:
  26. alert(window.document.body.className);
  27. </script>
  28. <span>Appears after the alert() call.</span>
  29. </body>
  30. </html>
  31.  
  32. <script>
  33. $(document).ready(function() {
  34. $("body").addClass("active");
  35. });
  36. </script>
  37. <body>
  38. ..
  39. ..
  40. ..
  41. </body>
  42.  
  43. <body class="active">
  44. </body>
  45.  
  46. <script type="text/javascript">
  47. document.documentElement.className = 'active';
  48. </script>
Add Comment
Please, Sign In to add comment