JavaScript Tutorial For Beginners #33 – Traversing the DOM




Hey all, in this JavaScript tutorial for beginners, I’ll explain how we can reach into the DOM and grab content (nodes) from the DOM tree, such as elements, classes and ID’s. And I’ll also explain how we can search ‘within’ tags under different scopes to find child elements.

In this tutorial we’ll learn three JavaScript methods (functions) to do that:

getElementsByTagName() – returns an array of objects
getElementsByClassName() – returns an array of objects
getElementById() – returns a single object

SUBSCRIBE TO CHANNEL – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1

========== JavaScript for Beginners Playlist ==========

========== CSS for Beginners Playlist ==========

========== HTML for Beginners Playlist ==========

========== The Net Ninja ============

For more front-end development tutorials & to black-belt your coding skills, head over to – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg or http://thenetninja.co.uk

========== Social Links ==========

Twitter – @TheNetNinja – https://twitter.com/thenetninjauk

Original source


28 responses to “JavaScript Tutorial For Beginners #33 – Traversing the DOM”

  1. Can anyone help? I'm stuck n this video

    I get an error, this is my code:

    var myContentDivs = document.getElementsByClassName("content");
    // this returns html collection

    var myH2 = myContentDivs[1].getElementsByTagName("h2");
    // Returns an Error:

    VM1014:1 Uncaught TypeError: Cannot read property 'getElementsByTagName' of undefined
    at <anonymous>:1:29

Leave a Reply