Skip to content

Instantly share code, notes, and snippets.

@natevw
Created June 20, 2019 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natevw/43219674e93dfacc863645c411797a83 to your computer and use it in GitHub Desktop.
Save natevw/43219674e93dfacc863645c411797a83 to your computer and use it in GitHub Desktop.
Testing whether querySelectorAll finds multiple elements with #non_unique id.
<!doctype html>
<html><head>
<meta charset="utf-8">
<title>Testing multiple ids</title>
</head><body>
<p id="one">
<span id="not_unique">One</span>
</p>
<p id="two">
<span id="not_unique">Two</span>
</p>
<script>
let docResults = document.querySelectorAll('#not_unique'),
divResults = document.querySelectorAll('#two #not_unique'),
divResults = document.getElementById('#two') #not_unique'),
document.write(`doc: ${docResults.length}, div: ${divResults.length}`);
console.log({docResults,divResults});
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment