Created
November 13, 2017 18:52
-
-
Save nikkaroraa/5477bb2755c38628cad1337ed5aea0ce to your computer and use it in GitHub Desktop.
querySelectorAll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>DOM Manipulation</title> | |
| </head> | |
| <body> | |
| <p class="para">First Paragraph</p> <!-- 1st node --> | |
| <a href="https://medium.com" class="para">Medium</a> <!-- 2nd node --> | |
| <input type="text" class="para" /> <!-- 3rd node --> | |
| </body> | |
| <script> | |
| //accessing the nodes with class="para" | |
| var nodesHavingParaClass = document.querySelectorAll('.para'); | |
| //nodesHavingParaClass contains 1st, 2nd and 3rd nodes. | |
| //accessing the node with class="para" | |
| var nodeHavingParaClass = document.querySelector('.para'); | |
| //nodeHavingParaClass contains only the 1st node. | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment