From the course: Learning App Building with Vanilla JavaScript

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Select and modify elements with querySelector

Select and modify elements with querySelector - JavaScript Tutorial

From the course: Learning App Building with Vanilla JavaScript

Start my 1-month free trial

Select and modify elements with querySelector

- [Instructor] So we're going to start replacing jQuery selectors in our app with Vanilla JavaScript selectors. So in script.js, scrolling through there are a number of places throughout that use the jQuery dollar selector syntax to select elements. Now a jQuery selector returns a jQuery object, which has jQuery methods and properties in addition to the content of the selected element or elements. By contrast, when you use a Vanilla JavaScript selector, you get back a reference to the element or elements and that's it. Now in some locations in our code where we use jQuery selectors, it's not as simple as changing them to Vanilla JavaScript, because the code that follows expects a jQuery object rather than simply an element reference. So for example here on line 18 where we're creating an event listener for an element, the code that follows the selector uses a jQuery method, click, that expects a jQuery object. So we can't simply swap that out for Vanilla JavaScript. But there are a…

Contents