Method: 1. Use the "document.getElementById("id value")" statement to obtain the h2 element object based on the id value; 2. Use "h2 element object.innerHTML="new title content"" or "h2 Element object.innerText="New title content"" statement can be modified.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In javascript, if you want to modify the content of a tag, you can use:
innerHTML attribute
innerText attribute
Implementation code:
<h2 id="h2">旧h2标题内容</h2> <script> var h=document.getElementById("h2"); // h.innerHTML="新标题内容"; h.innerText="新标题内容"; </script>
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to modify h2 title in javascript. For more information, please follow other related articles on the PHP Chinese website!