Latest web development tutorials

HTML DOM Methods

The method is an action that we can perform on the node (HTML elements).


Programming Interface

By JavaScript (and other programming languages) to HTML DOM access.

All HTML elements are defined as an object, and the programming interface is object method and object properties.

The method is an operation (such as adding or modify elements) that you can perform.

Property is that you can get or set value (for example, node name or content).


getElementById () method

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

Examples

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

try it"


HTML DOM objects - methods and properties

Some commonly used HTML DOM methods:

  • getElementById (id) - Get node (element) with the specified id
  • appendChild (node) - insert a new child node (element)
  • removeChild (node) - Removes the child node (element)

Some commonly used HTML DOM attributes:

  • innerHTML - node (element) text value
  • parentNode - nodes (elements) of the parent node
  • childNodes - node (element) of the child node
  • attributes - node (element) attribute node

In this tutorial you will learn more about the next chapter property.


Real-life objects

A person is an object.

One approach might be to eat (), sleep (), work (), play (), and so on.

These methods all have, but they will be executed at different times.

A person's property, including their name, height, weight, age, sex and so on.

Everyone has these properties, but their values ​​vary.


Some DOM object methods

Here are some common methods you learned in this tutorial to:

method description
getElementById () Returns the element with the specified ID.
getElementsByTagName () Returns a list of nodes (set / node array) containing all elements with the specified tag name.
getElementsByClassName () Returns a list of all of the elements with the specified node contains the name of the class.
appendChild () To add a new child node to the specified node.
removeChild () Removes the child node.
replaceChild () Replace child nodes.
insertBefore () Insert a new child node in front of the specified child node.
createAttribute () Create attribute node.
createElement () Create an element node.
createTextNode () Create a text node.
getAttribute () Returns the specified attribute values.
setAttribute () To set or modify the specified value of the specified property.