

The static collection did not increase after the appearance of a new div in the document. Let divs = document.querySelectorAll('div') document.getElementsByName(name) returns elements with the given name attribute, document-wide.elem.getElementsB圜lassName(className) returns elements that have the given CSS class.The tag parameter can also be a star "*" for “any tags”. elem.getElementsByTagName(tag) looks for elements with the given tag and returns the collection of them.So here we cover them mainly for completeness, while you can still find them in the old scripts. Today, they are mostly history, as querySelector is more powerful and shorter to write. There are also other methods to look for nodes by a tag, class, etc. Let chapter = document.querySelector('.chapter') // LIĪlert(chapter.closest('.contents')) // DIVĪlert(chapter.closest('h1')) // null (because h1 is not an ancestor)
