In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to add nodes in Javascript". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to add nodes in Javascript" can help you solve your doubts.
How to add nodes to Javascript
Javascript provides two ways to add nodes:
Method description
InsertBefore () inserts a new node in front of the specified node
AppendChild () inserts a new child node at the end of the specified node (the original child node remains the same)
InsertBefore ()
The insertBefore () method inserts a new node in front of the specified node.
Syntax:
ParentNode.insertBefore (newNode, thisNode)
Parameter / return value description:
Parameter / return value description
ParentNode parent node
The new node to be added by newNode
ThisNode current node (specified node)
True is returned for successful insertion, and false is returned for failure.
For example, the statement to add a node before the node of id= "dome" is:
How to add nodes to Javascript
Var ele_div=document.createElement ("div")
Var thisNode=document.getElementById ("demo")
This [XSS _ clean] .insertBefore (ele_div, thisNode)
Note: insertBefore () is a method for the parent of the current node. When you add a node, you need to know not only the current node, but also the parent node of the current node. In general, the parent node can be obtained through thisNode [XSS _ clean].
For example, keep adding new nodes in front of the specified node:
Div id= "demo" >
Div id= "thisNode" > Click here to add a new node / div >
/ div >
Script type= "text/javascript" >
Document.getElementById ("thisNode") .onclick=function () {
Var ele_div=document.createElement ("div")
Var ele_text=document.createTextNode ("this is the new node")
Ele_div.appendChild (ele_text)
This [XSS _ clean] .insertBefore (ele_div, this)
}
/ script >
After reading this, the article "how to add nodes in Javascript" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.