Home >Web Front-end >Front-end Q&A >How to modify the content of h4 tag in javascript

How to modify the content of h4 tag in javascript

青灯夜游
青灯夜游Original
2022-02-16 15:48:412967browse

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.

How to modify the content of h4 tag in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

The

tag defines the fourth-level heading in an HTML document.

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>

How to modify the content of h4 tag in javascript

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

Statement:
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