DEV Community

Cover image for Getting DOM Elements using JavaScript

Getting DOM Elements using JavaScript

Atta on July 25, 2019

This post was originally published on attacomsian.com/blog. The Document Object Model (DOM) is a programming interface for HTML and XML documen...
Collapse
 
kevinhch profile image
Kevin

Another way:
const inputs = [...document.getElementById('signup').getElementsByTagName('input')];
// iterate over HTMLCollection
inputs.forEach(element => {
console.log(element);
});

Collapse
 
attacomsian profile image
Atta

Spread operator is very useful. Thank you for the tip 🙌

Collapse
 
winniebosy profile image
Winnie Magoma

Clear explanations of DOM elements in JS...Thanks 😀

Collapse
 
attacomsian profile image
Atta

✌️

Collapse
 
aaron_powell profile image
Aaron Powell

I swapped from getById/Classname to query selector a while ago. Do you know if Query selector is faster/more efficient? Thanks!