Home >Web Front-end >Front-end Q&A >How to modify the content of h4 tag in javascript
Modification method: 1. Use the "document.getElementById("id value")" statement to select the h4 tag node based on the id attribute value; 2. Use "h4 tag node.innerHTML = "Modified content"; " statement can modify the content of the h4 tag.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The
So how does javascript modify the content of the h4 tag?
Implementation idea:
First select the h4 node
Then use the innerHTML attribute to modify the node content
Implementation code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <h1>一级标题</h1> <h2>二级标题</h2> <h3>三级标题</h3> <h4 id="h4">四级标题</h4> <h5>五级标题</h5> <h6>六级标题</h6> <button onclick="myFunction()"> 修改h4标签的内容</a> <script type="text/javascript"> function myFunction() { var h4 = document.getElementById("h4"); h4.innerHTML = "新四级标题,内容已修改"; } </script> </body> </html>
[Related recommendations: javascript learning tutorial 】
The above is the detailed content of How to modify the content of h4 tag in javascript. For more information, please follow other related articles on the PHP Chinese website!