JS Operation Dom

Source: Internet
Author: User

what is DOM?
What is called Dom,dom is the Document Object model, which is a set of API interfaces based on browser programming (in this tutorial, which can be said to be DHTML programming), the recommended standards for the Web, and each browser has some subtle differences, Among them, Mozilla's browser is closest to the standard. Simple JavaScript can be combined with DOM to do DHTML programming to make beautiful effects and apply to the Web. This is almost the same as any other language, just as C + + requires library support. Otherwise, it's a purely grammatical study.

Therefore, it is necessary to have a certain understanding of the DOM in order to apply JavaScript to the Web.

Let me tell you a little bit about how DOM operates:

  Create a Node

var createnode = document.createelement ("div");

var createTextNode = document.createTextNode ("Hello World");

Createnode.appendchild (createTextNode);

Document.body.appendChild (CreateNode);

Document.documentElement.appendChild (CreateNode);

  Inserting nodes

var createnode = document.createelement ("div");

var createTextNode = document.createTextNode ("Hello World");

Createnode.appendchild (createTextNode);

var div1 = document.getElementById ("Div1");

Document.body.insertBefore (CREATENODE,DIV1);

  Replace element

var replacechild = Document.body.replaceChild (CREATENODE,DIV1);

  Delete Element

var removechild = Document.body.removeChild (DIV1);

Finally, let us summarize:

The DOM standard is divided into 3 different parts:

    • Core DOM-a standard model for any structured document

    • XML DOM-a standard model for XML documents

    • HTML DOM-A standard model for HTML documents

All content in an HTML document is a node, based on the HTML DOM standard of the paper:

    • The entire document is a document node

    • Each HTML element is an element node

    • Text within an HTML element is a text node

    • Each HTML attribute is an attribute node

    • Comment is a comment node

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

If you do not understand, please click the following reference:

Reference

JS Operation Dom

Related Article

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.