Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use innerHTML in JavaScript

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "how to use innerHTML in JavaScript", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use innerHTML in JavaScript" article.

How to use JavaScript innerHTML

(1) innerHTML can insert HTML code directly into specified nodes.

Syntax:

NodeObject [XSS _ clean] = HTMLCode

Where nodeObject is the node object and HTMLCode is the HTML code.

Note: innerHTML will overwrite the original HTML code.

For example, add three new nodes to the node of id= "demo":

Div id= "demo" >

Div > Click here to add a new node / div >

/ div >

Script type= "text/javascript" >

Document.getElementById ("demo") .onclick=function () {

This [XSS _ clean] = "div > this is the new node 1/div > div > this is the new node 2/div > div > this is the new node 3/div >"

}

/ script >

How does Javascript get sibling nodes

The so-called sibling node refers to the previous node or the next node of the current node.

Get the previous node

In Javascript, the previous node is obtained through previousSibling.

Syntax:

NodeObject.previousSibling

Where nodeObject is the node object (element node).

Under IE, blank nodes between nodes (spaces, carriage returns, and Tab keys) are ignored; not under browsers that follow the W3C specification (Chrome, FireFox, Safari, etc.).

Take a look at the following code:

# demo {

Height:180px

Width:250px

Padding:0px 10px 10px 10px

Border:1px solid # ccc

Background-color:#ededed

}

# demo div {

Height:50px

Width:250px

Margin-top:10px

Text-align:center

Line-height:50px

Background-color:#ccc

}

The above is about the content of this article on "how to use innerHTML in JavaScript". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report