HTML DOM Elements


JavaScript HTML DOM Elements refer to the individual elements or nodes that make up an HTML document, such as headings, paragraphs, images, forms, and more. These elements are represented as objects in the Document Object Model (DOM), which is a programming interface that provides a structured representation of an HTML document.

With JavaScript and the DOM, you can access, manipulate, and dynamically update these elements to create interactive and dynamic web pages.


innerHTML

The innerHTML property is used to access or modify the HTML content within an element. It allows you to retrieve the HTML content as a string or set new HTML content for the element.

Example

Preview

innerText

The innerText property is used to access or modify the text content of an element, excluding any HTML tags or markup. It represents only the visible text within the element, ignoring any styling or structural elements.

Example

Preview

style

This property allows you to get or set the style of an element. You can use this property to change the color, font, size, and other visual aspects of an element.

Example

Preview

classList

This property returns a collection of the class names for an element. You can use this property to add or remove classes from an element.

Example

Preview

getAttribute()

This method returns the value of the specified attribute for an element.

Example

Preview

setAttribute()

This method sets the value of the specified attribute for an element.

Example

Preview

appendChild()

This method adds a new child node to an element.

Example

Preview

removeChild()

This method removes a child node from an element.

Example

Preview

addEventListener()

This method attaches an event listener to an element. When the specified event occurs, the function is executed.

Example

Preview

querySelector()

This method returns the first HTML element that matches the specified selector.

Example

Preview