Favorites

DOM Element Interface

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Element
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

The Element interface is the base for every element in a document, such as div or p. It provides the properties and methods shared by all elements, like classList, querySelector() and getAttribute().

Description

The Element interface is the most general base class from which all element objects in a Document inherit. It only has the methods and properties common to every kind of element. More specific interfaces build on it: HTMLElement for HTML elements, with subtypes such as HTMLInputElement, and SVGElement for SVG.

You usually get elements from the document with methods such as document.querySelector() or document.getElementById(), or create them with document.createElement(). With an element you can read and change its attributes, classes and content, find other elements inside it, and respond to events.

Element inherits from Node, which in turn inherits from EventTarget, so every element also has methods such as appendChild() and addEventListener().

Inheritance

Element inherits properties and methods from Node.

Properties

NameDescription
Element.childrenThe children property returns a live collection of an element's child elements, ignoring text and comments.
Element.classListThe classList property gives a live list of an element's CSS classes, with methods to add, remove, toggle and check classes.
Element.classNameThe className property gets or sets an element's class attribute as a single string.
Element.firstElementChildThe firstElementChild property returns an element's first child element, skipping text nodes.
Element.idThe id property gets or sets an element's id attribute.
Element.innerHTMLThe innerHTML property gets or sets the HTML markup inside an element.
Element.nextElementSiblingThe nextElementSibling property returns the element immediately after an element in its parent, skipping text.
Element.outerHTMLThe outerHTML property gets the HTML of an element including its own tag, or replaces the whole element when set.
Element.tagNameThe tagName property returns the name of an element's tag, in upper case for HTML elements.

Methods

NameDescription
Element.append()The append() method adds one or more nodes or text strings to the end of an element.
Element.before()The before() method inserts nodes or text just before an element, as siblings.
Element.closest()The closest() method searches up the tree from an element and returns the nearest ancestor, or the element itself, that matches a CSS selector.
Element.getAttribute()The getAttribute() method returns the value of an attribute on an element, or null if it isn't set.
Element.getBoundingClientRect()The getBoundingClientRect() method returns the size of an element and its position relative to the viewport.
Element.hasAttribute()The hasAttribute() method checks whether an element has a given attribute.
Element.insertAdjacentHTML()The insertAdjacentHTML() method parses an HTML string and inserts the result at a given position relative to an element, without replacing existing content.
Element.matches()The matches() method checks whether an element would be selected by a given CSS selector.
Element.prepend()The prepend() method adds one or more nodes or text strings at the start of an element, before its first child.
Element.querySelector()The querySelector() method returns the first element inside an element that matches a CSS selector, or null if nothing matches.
Element.querySelectorAll()The querySelectorAll() method returns a list of every element inside an element that matches a CSS selector.
Element.remove()The remove() method removes an element from the page.
Element.removeAttribute()The removeAttribute() method removes an attribute from an element.
Element.replaceWith()The replaceWith() method replaces an element in the page with other nodes or text.
Element.scrollIntoView()The scrollIntoView() method scrolls the page, and any scrollable containers, so that an element becomes visible.
Element.setAttribute()The setAttribute() method sets the value of an attribute on an element, adding the attribute if it doesn't exist.
Element.toggleAttribute()The toggleAttribute() method adds a boolean attribute if it's missing or removes it if it's present.

Events

NameDescription
Element: click eventThe click event fires when an element is activated by a mouse click, a tap, or the Enter or Space key on buttons and links.
Element: keydown eventThe keydown event fires when a key is pressed while an element (or something inside it) has focus, and repeats while the key is held.

Example

<p id="intro" class="lead">Hello <strong>world</strong></p>
const el = document.querySelector('#intro');

console.log(el.tagName);
console.log(el.id, el.className);
console.log(el.textContent);
console.log(el instanceof Element);

el.classList.add('highlight');
el.setAttribute('title', 'Greeting');
console.log(el.outerHTML);

Browser Support

The following information will show you the current browser support for the Element interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee