Get Elements By Tag Name

Examples

The method returns a collection of all elements with a specified tag name.

// Get All Elements By Tag Name
const allElements= document.getElementsByTagName("*");
// Get Elements By Tag Name div
    let element = document.getElementsByTagName('div');

// Get Elements By Tag Name a
    let element = document.getElementsByTagName('a');

// Get Elements By Tag Name article
    let element = document.getElementsByTagName('article');

// Get Elements By Tag Name p
    let element = document.getElementsByTagName('p');

// Get Elements By Tag Name section
    let element = document.getElementsByTagName('section');

// Get Elements By Tag Name li
    let element = document.getElementsByTagName('li');

// Get Elements By Tag Name ul
    let element = document.getElementsByTagName('ul');

// Get first list item.
 const list = document.getElementsByTagName("UL")[0];
 list.getElementsByTagName("li")[0].innerHTML = "Text";

Leave a Reply