JavaScript Query Selector


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

This will only work in FF 3.5 and web-kit browsers. (post 06/20/2009)


Copy this code and paste it in your HTML
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. </head>
  6. <body>
  7.  
  8. <p id="hello">
  9.  
  10. </p>
  11.  
  12. <p class="goodbye">
  13.  
  14. </p>
  15.  
  16. <script>
  17. // Gather the elements
  18. var i = document.querySelector("p#hello");
  19. i.innerHTML = "Hello World";
  20.  
  21. var j = document.querySelector("p.goodbye");
  22. j.innerHTML = "Good Bye!";
  23. </script>
  24.  
  25. </body>
  26. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.