Standard DOM and HTML DOM summary __html

Source: Internet
Author: User

There are two ways to manipulate HTML page elements: The standard DOM method and the HTML DOM method

The standard DOM provides a unified operational interface: The createelement appendchild setattribute removeattribute nodename HTML DOM provides a variety of encapsulated objects: Image Select Option

1. When manipulating nodes: typically using standard DOM operations, such as:

Create Node
var inputnode = document.createelement ("input");
//Queries node
var node = document.getElementById ("Node_ ID ");
Delete node
node.removechild (Childnode);

Of course, you can also use HTML DOM operations, such as:

Create Node
var imagenode = new Image ();
Image.src  = "Img.png";

2. When manipulating properties: typically using HTML DOM operations, such as:

node.id = "button";
Node.value = "click button";
Add a Click event for node, Clickfunction () is a parameterless method
Node.onclick = "Clickfunction";
Add a Click event for node, clickfunction (ID) is a parametric method
Node.onclick = function () {clickfunction (id)};
Note: When using HTML DOM operations to add a click event to a node, note that if the Click event is a parameterless method, it can be invoked directly through the method name, and if the Click event is a parametric method, the anonymous method needs to be created first and then called in the anonymous method.

Of course, you can also use standard DOM operations, such as:

Node.setattribute ("id", "button");
Node.setattribute ("Value", "click button");
Add a Click event for node, Clickfunction () is a parametric method
Node.setattribute ("onclick", "Javascript:clickfunction (ID)");

Note: If you need to delete a property, you can only use the RemoveAttribute () method provided by the standard DOM operation, and the HTML DOM operation does not provide related functionality

3. Summary: The HTML DOM encapsulates standard HTML element objects (properties, methods) but does not implement all of the functionality, with the advantage of simplifying the common element objects, with the disadvantage of not supporting all elements, but the standard DOM is omnipotent.


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.