The universal selector (*
), matches the name of any element type. It matches any single element in the document tree. Some ways it can be used:
document.querySelectorAll("*")
– to get all elements.document.querySelectorAll("body *")
– to get all descendant elements of body element.
Example – use universal selector to get all DOM nodes
<html> <body> <script> function printAllNodes() { var elementList = document.querySelectorAll("*"); for (i = 0; i < elementList.length; ++i) { document.querySelector("pre").innerText += elementList[i].nodeName + "\n"; } } window.addEventListener('load', printAllNodes); </script> <pre></pre> </body> </html>