Home > Web Front-end > JS Tutorial > body text

How to modify div text with JavaScript

青灯夜游
Release: 2021-10-08 16:09:01
Original
6528 people have browsed it

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

2. Modify the text content of the div tag

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

Complete implementation code:







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

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!

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