HTML DOM Methods

Source: Internet
Author: User

Tag: Name insert parent node property for set nod description RTB

Methods are actions that we can perform on a node (HTML element).

Programming interface

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

All HTML elements are defined as objects, while programming interfaces are object methods and object properties.

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

A property is a value that 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 HTML DOM objects-Methods and properties

Some common HTML DOM methods:

    • getElementById (ID)-Gets the node (element) with the specified ID
    • AppendChild (node)-Insert a new child node (element)
    • RemoveChild (node)-Delete child nodes (elements)

Some common HTML DOM properties:

    • InnerHTML-Text value of the node (element)
    • ParentNode-parent node of the node (element)
    • ChildNodes-Child nodes of nodes (elements)
    • Attributes-node (element) attribute node

You'll learn more about attributes in the next chapter of this tutorial.

The object of real life

A person is an object.

The human method may be eat (), sleep (), work (), play (), and so on.

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

A person's attributes include name, height, weight, age, gender, and so on.

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

Some DOM object methods

Here are some common ways you'll learn in this tutorial:

td> returns the element with the specified ID.
method Description
getElementById ()
getelementsbytagname () Returns a list of nodes (a collection/node array) that contains all the elements with the specified label name.
getelementsbyclassname () Returns a list of nodes that contain all the elements with the specified class name.
appendchild () adds a new child node to the specified node.
removechild () deletes child nodes.
replacechild () replaces child nodes.
insertbefore () inserts a new child node in front of the specified child node.
createattribute () creates an attribute node.
createelement () creates an element node.
createtextnode () creates a text node.
getattribute () returns the specified property value.
setAttribute () Sets or modifies the specified property to the specified value.
var Element=document.getelementbyid ("Intro");

HTML DOM Methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.