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

Unlock the full course today

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

Select groups of elements with getElementsByName

Select groups of elements with getElementsByName

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

Start my 1-month free trial

Select groups of elements with getElementsByName

- [Instructor] In this video I'll be using JavaScript to interact with the DOM by using one of its native methods, the getElementsByName. This method returns a collection of elements or an array of elements that contain the value of the name attribute. The name attribute is becoming deprecated. It's obsolete because it's been replaced by the id and so that's why in HTML5 it's not very, very popular. But it's still around, especially in forms. So most of your form controls still use the name attribute to assign a sort of value to each of those tags. So for example in this form here, we're going to create a function to validate this form. And this is a very, very popular way of validating forms. In the old days, you used JavaScript to do that, it was very complicated. But it came along until HTML5 and now you can validate forms very easily just by putting the keyword required to any field and that takes care of it. So for example, this form. If I click this signup button, you'll see…

Contents