From the course: The DOM in JavaScript, jQuery, AngularJS, and React

Unlock the full course today

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

Select elements with getElementsByTagName

Select elements with getElementsByTagName

From the course: The DOM in JavaScript, jQuery, AngularJS, and React

Start my 1-month free trial

Select elements with getElementsByTagName

- [Instructor] One of the things that you can do with the DOM is, it allows you to find out how many types of tags there are in the DOM. And it's very, very useful sometimes. So you want to find out how many paragraph tags and if they're input tags, what type are they? Is it a button type? Is it a text type? Is there a radio button type or something like that? So those are really, really handy sometimes. And so in this exercise, we're going to use the getElementsByTagName. And we want to find out how many types of tags in this form there are of the type text only. The getElementsByTagName turns an array of elements or a collection of elements that contain the specified tag name. If you want to, let's just say, look up all the paragraph tags, then that's what you will get. So in this form here, we're going to find out how many input fields are in this form and then we're going to mark all of those fields to have the type of text only. So let's head over to brackets and do our code. I'm…

Contents