From the course: JavaScript Essential Training

Unlock the full course today

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

Access elements using older methods

Access elements using older methods - JavaScript Tutorial

From the course: JavaScript Essential Training

Start my 1-month free trial

Access elements using older methods

- [Instructor] In tutorials and code examples, and even live code you will often find two other methods used to access elements, getelementsbyClassName and getelementbyId. Notes that get elements by class name has the plural of elements whereas the by id one has the singular of element. These two methods used to be the only tools we had for accessing elements using classes and ids and they still work, but queryselector and queryselectorall were introduced to simplify this process and remedy some of the shortcomings of these older methods. That said they still work fine they're just falling out of favor because the queryselector method work better and easier. Lets look at how these older methods work, getelementsbyClassName returns an array-like object of all the nodes or child elements matching the query. The query is string of space separated class names. Looking at the exercise file for this moving you will see I have…

Contents