Javascript DOM Programming Art reading notes 16/04/02

Source: Internet
Author: User

Last Updated 2016-04-02 16:14:06

Objective:

This section tells you how to dynamically insert content into HTML by using JSP syntax to change the existing content of HTML.

If we dig deeper into the DOM tree, we know that HTML content actually exists as a node tree, changing the content, that is, adding a new node to the node tree.

Of course, we use JSP to add content to the Web page, and will not change the original HTML document

Two important functions for creating a node

Createelemnt ("x") creates an element node that returns a reference to the newly created node

createTextNode ("text") to Create a text node

For example, to create a P node, we use document as the parent node

var // para a reference to the newly created "P"

There is nothing inside this p-node, and this element is free from the document, and we cannot see it on the Web page, but this element does exist.

Of course, we can setattribute to this new element node. Adding attribute Nodes

Important functions for mounting newly created nodes built-in (cannot attach nodes to text nodes)

Appenchild (NewNode) general formula for parent.appendchild ("NewNode")

InsertBefore (Newnode,targetnode) inserted before TargetNode

Create a new Insert function with built-in functions InsertAfter

function  InsertAfter (newnode,targetnode) {  var parent = Taretnode.parentnode;   if(targetnode.node==parent.lastchild) {parent.appendchild (newnode);  }Else{parent.insertbefore (Newnode,targetnode.nextsiblingnode); }}

Javascript DOM Programming Art reading notes 16/04/02

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.