Home  >  Article  >  Web Front-end  >  How to modify div text with JavaScript

How to modify div text with JavaScript

青灯夜游
青灯夜游Original
2021-10-08 16:09:016505browse

JavaScript method to modify div text: 1. Use the "document.getElementById('id value')" statement to obtain the div object based on the id value of the div tag; 2. Use "div object.innerHTML=" new text The content "" statement modifies the div text.

How to modify div text with JavaScript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to modify div text in JavaScript

1. Get the div element object

Use getElementById () Get the object based on the id value

document.getElementById('div')

2. Modify the text content of the div tag

div对象.innerHTML="新div文本内容"

Complete implementation code:







     
旧div文本内容,点击一下进行修改

Effect Picture:

How to modify div text with JavaScript

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to modify div text 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