offline version v3


148 of 264 menu

getElementsByTagName method

The getElementsByTagName method allows you to get page elements by a tag name. With the retrieved elements, you can perform various manipulations: change their text, attributes, CSS styles, and so on.

Syntax

document.getElementsByTagName(tag name);

Example

Let's get all the paragraphs and change their text using the property innerHTML:

<p>elem 1</p> <p>elem 2</p> <p>elem 3</p> let elems = document.getElementsByTagName('p'); for (let elem of elems) { elem.innerHTML = '!!!'; }

The code execution result:

<p>!!!</p> <p>!!!</p> <p>!!!</p>

See also

enru