Posted By

nerdfiles on 12/24/09


Tagged

javascript GetElementsByClassName html5


Versions (?)

testing getElementsByClassName in HTML5


 / Published in: JavaScript
 

  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  5. <title>Classing </title>
  6. <script type="text/javascript">
  7. (function(){
  8.  
  9. $classing = {
  10. //initializer function
  11. init: function(className) {
  12. window.onload = function() {
  13. var html = $classing.getByClass(className)[0].innerHTML.replace(/^\s+|\s+$/g, "");
  14. alert( html );
  15. }
  16. },
  17. //testing getElementsByClassName extension to HTML
  18. getByClass: function(className) {
  19. var elems = document.getElementsByClassName(className);
  20. return elems;
  21. }
  22. }
  23.  
  24. $classing.init('class');
  25.  
  26. })();
  27. </script>
  28. </head>
  29. <body>
  30. <div class="class">
  31. <p>I am a paragraph lost within a division's space.</p>
  32. </div>
  33. <div class="class">
  34. <p>I am a paragraph lost within a division's space.</p>
  35. </div>
  36. </body>
  37. </html>

Report this snippet  

You need to login to post a comment.