Easy Tutorial
❮ Htmldom Intro Htmldom Properties ❯

HTML DOM Methods


HTML DOM methods are actions that we can perform on nodes (HTML elements).

HTML DOM properties are values that we can set and modify on nodes (HTML elements).


Programming Interface

The HTML DOM can be accessed via JavaScript (and other programming languages).

All HTML elements are defined as objects, and the programming interface consists of object methods and object properties.

Methods are actions you can perform (such as adding or modifying elements).

Properties are values you can get or set (such as the name or content of a node).


getElementById() Method

The getElementById() method returns the element with the specified ID:

Example

var element = document.getElementById("intro");

HTML DOM Objects - Methods and Properties

Some commonly used HTML DOM methods:

Some commonly used HTML DOM properties:

You will learn more about properties in the next chapter of this tutorial.


Real-Life Objects

A person is an object.

A person's methods might include eat(), sleep(), work(), play(), etc.

Everyone has these methods, but they are performed at different times.

A person's properties include name, height, weight, age, gender, etc.

Everyone has these properties, but their values vary from person to person.


Some DOM Object Methods

Here are some commonly used methods that you will learn in this tutorial:

Method Description
getElementById() Returns the element with the specified ID.
getElementsByTagName() Returns a node list (collection/array of nodes) containing all elements with the specified tag name.
getElementsByClassName() Returns a node list containing all elements with the specified class name.
appendChild() Adds a new child node to the specified node.
removeChild() Deletes a child node.
replaceChild() Replaces a child node.
insertBefore() Inserts a new child node before the specified child node.
createAttribute() Creates an attribute node.
createElement() Creates an element node.
createTextNode() Creates a text node.
getAttribute() Returns the specified attribute value.
setAttribute() Sets or modifies the specified attribute to the specified value.
❮ Htmldom Intro Htmldom Properties ❯