JavaScript creation Node

Source: Internet
Author: User

1.JavaScript Creating nodes

CreateElement (); Note: Create an element node.

For example:

var v = document.createelement ("P");

createTextNode (); Note: Create a text node.

For example:

var v = document.createtextnode ("Everyone good");

2.js node operation

AppendChild (); Note: Add a child node to the current node

var p = document.createelement ("P");

var text = document.createTextNode ("Everyone good");

P.apendchild (text); Note: add

RemoveChild (); Delete child nodes

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

var p = document.createelement ("P");

Div.removechild (P);

ReplaceChild (); Note: Replace child nodes

var p = document.createelement ("P");

var text = document.createTextNode ("Everyone good");

P.apendchild (text); Note: Add text to P

var Text1 = document.createTextNode ("Good for You");

P.apendchild (Text1,text); Note: This will change the text to Text1.

InsertBefore (); Before inserting one node into another node.

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

var p = document.createelement ("P");

Div.apendchild (P); Note: Add P to Div, this time p position in Div is the first

var P1 = document.createelement ("H1");

Div.insertbefore (P,P1); Note: This puts H1 in front of P, where p is the second position in the Div.

2.JavaScript element content and properties operations

InnerHTML; Gets the HTML for the specified element. ClassName; Gets the class attribute of the specified element. style; Gets the style style of the specified element. GetAttribute (); Gets the property value of the specified element. SetAttribute (); Sets a property for the new element. RemoveAttribute (); Deletes the properties of the specified element.

For example

<div id = "DIV1" >abc<div/>

document.getElementById ("Div1"). innerhtml= "CBA";

document.getElementById ("Div1"). SetAttribute ("style", "Color: #000;");

JavaScript creation Node

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.