Home >Web Front-end >Front-end Q&A >How to replace div content with javascript

How to replace div content with javascript

藏色散人
藏色散人Original
2021-11-01 15:36:303866browse

How to replace div content with JavaScript: 1. Define a div node; 2. Get the div node; 3. Replace the div content with "dt.innerHTML = "abc";".

How to replace div content with javascript

The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

How to replace div content with javascript?

Replace content by updating innerHTML information

1. Define a div node

<div id=&#39;test&#39;>123</div>

2. Obtain the div node

var dt = document.getElementById(&#39;test&#39;);//通过id获取该div

3. Replace the content of the div

dt.innerHTML = "abc";//把123替换成abc

Recommended study: "javascript basics Tutorial

The above is the detailed content of How to replace div content with javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Is nodejs js?Next article:Is nodejs js?