Home > Web Front-end > JS Tutorial > How to modify h2 title in javascript

How to modify h2 title in javascript

青灯夜游
Release: 2021-12-07 15:03:38
Original
3649 people have browsed it

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.

How to modify h2 title in javascript

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

How to modify h2 title in javascript

[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!

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