DEV Community

Cover image for JavaScript DOM - Part 6 - Get Elements By TagName [video + article]

JavaScript DOM - Part 6 - Get Elements By TagName [video + article]

Tharun Shiv on May 22, 2020

This is going to be a multi-part Video + article tutorial series on JavaScript DOM. You're reading Part 6 You can read Part 5 here: ...
Collapse
 
chandrika56 profile image
Jaya chandrika reddy •

Looking forward for the Query Selectors 😊 Subscribed to the YouTube Channel 👍

Collapse
 
praveenreddy1798 profile image
praveenreddy1798 •

yep same here

Collapse
 
developertharun profile image
Tharun Shiv •

Thank you

Collapse
 
venkat121998 profile image
venkat anirudh •

yeah

Collapse
 
developertharun profile image
Tharun Shiv •

Thank you Venkat

Collapse
 
developertharun profile image
Tharun Shiv •

Thanks!

Collapse
 
andogq profile image
Tom Anderson •

Nice article! Just thought I'd add to the iteration bit:

Any DOM selector that returns mutlple objects (getElementsByTagName, getElementsByClassName ect) return a HTMLCollection object, which is different from an array, lacking all of the useful prototype functions like forEach which would make iteration easier and cleaner as opposed to a for loop.
To get around this, I like to use the ES6 spread operator on the result of the DOM function, effectively 'converting' it into a normal JS array, allowing me to operate and iterate over it as usual! See below for an example!

let para = [...document getElementsByTagName("p")];
para.forEach(p => {
    ... 
});
Collapse
 
developertharun profile image
Tharun Shiv •

That's a beauty! Thanks for contributing 🙂

Collapse
 
praveenreddy1798 profile image
praveenreddy1798 •

Good article. Subscribed to the YouTube Channel

Collapse
 
developertharun profile image
Tharun Shiv •

Glad it helped 😊

Collapse
 
venkat121998 profile image
venkat anirudh •

good one

Collapse
 
developertharun profile image
Tharun Shiv •

Thank you

Collapse
 
jreckers profile image
jreckers •

I have so been looking for information on these topics, as a newbie, I like the how’s and why’s of the DOM construct! Looking forward to more!

Collapse
 
developertharun profile image
Tharun Shiv •

Yep that's very exciting! Glad to help 🙂 If you would like video content on these , you can check them out on the YouTube channel : youtube.com/c/developerTharun