Skip to content

Instantly share code, notes, and snippets.

@nikkaroraa
Created November 13, 2017 18:52
Show Gist options
  • Save nikkaroraa/5477bb2755c38628cad1337ed5aea0ce to your computer and use it in GitHub Desktop.
Save nikkaroraa/5477bb2755c38628cad1337ed5aea0ce to your computer and use it in GitHub Desktop.
querySelectorAll
<!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