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

How to replace div content with javascript

藏色散人
Release: 2021-11-01 15:36:30
Original
3867 people have browsed it

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>
Copy after login

2. Obtain the div node

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

3. Replace the content of the div

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template