From the course: Vanilla JavaScript: Building on the Document Object Model (DOM)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Random access with querySelector()
From the course: Vanilla JavaScript: Building on the Document Object Model (DOM)
Random access with querySelector()
- [Instructor] Being able to efficiently locate specific elements in a complex DOM tree is one of the most frequent tasks you'll encounter when writing a vanilla JavaScript DOM application. Thanks to the W3C selectors recommendation, we can quickly sift through our DOM tree to access the elements we need. To make it easier to experiment with selectors, we'll build a simple query selector application that'll let us load some HTML, and then run querySelectorAll against it. We'll be starting from a base application that can load HTML into our page. So to demonstrate, I'm going to go ahead and grab some HTML from Donald Knuth's biography over here on Wikipedia. You'll see I'm using the developers tools to come in here to the tree, and grab basically the body of this article. I'm going to copy it. I'm going to come back over to the app. And I'm going to paste this into this text area, and you'll see it's being parsed and…