querySelector() method in javascript
querySelector() method is used to retrieve the first descendant element of the given element.
Example Explanation
- In the above example there is a table element, with th, tr and td elements.
- Here first we retrieves the table element (document.getElementById("tableID");) and stored in elem.
- Next we retrieves the first descendant element, using the th value (elem.querySelector("th").innerHTML).