Gurebu Bokofu Gurebu Bokofu - 1 year ago 40
Javascript Question

JavaScript: how to get the contains of the DOM w/o ID and class?

Is it possible to get only one DOM contains by tag name without ID and class?

As you know, in HTML5

and other new tags has been added, and thanks to it, to define the style of header or footer, assigning the class or id line
<div class="header">
becomes unnecessary.

E. g. I need to get the
contains, like

var test = document.getElementById("test");

by don't want to assign ID or class to header (nothing difference between
<div id="header">
<header id="header">
. However

var test = document.getElementsByTagName("header") ;

will not work (I mean will not save the
contains in variable value) even if there is only one header in the page.

Anything that I can to do?

Answer Source

will store all the header which is in the page in array.

var test = document.getElementsByTagName("header");
<header>first test</header>
<header>second test</header>

Reference link here