From the course: JavaScript: Enhancing the DOM (2013)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Working with named form elements
From the course: JavaScript: Enhancing the DOM (2013)
Working with named form elements
Selecting form elements is a little easier because forms can have and additional attribute called Name. Like with document images, the DOM provides a special object called document.forms. That's an array of form elements on the page. You can also get to any form element that has a name a little bit easier. So, let's take a look. I'm going to go over to my website, and I'll click on this Register page. Now from here, you can see that I have a form on the left side of this document. Let me pull up the developer tool by hitting Cmd+Option+I on a Mac, Ctrl+Alt+I on a PC. And then, I'm going to hit the Escape key to pull up the console, and I'll type in document.forms. Now, that gives me an array of all the forms in the current document. I've only got one form, so it's only returning one item. If I want to get into that element, I can say document forms and then the index. Since this is the first item, I'm going to use the index 0, because arrays are 0 indexed. Now, I can get to the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Selecting elements with getElementById4m 10s
-
(Locked)
Choosing elements by HTML tag3m 20s
-
(Locked)
Isolating elements by class name3m 12s
-
(Locked)
Querying CSS to select elements4m 54s
-
(Locked)
Working with named form elements3m 39s
-
(Locked)
Understanding nodeType, nodeName, and nodeValue4m 30s
-
(Locked)
Traversing up and down DOM nodes4m 40s
-
(Locked)
Targeting node elements2m 44s
-
(Locked)
-
-
-
-