Home > Article > Web Front-end > How to modify div text with JavaScript
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.
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:
[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!