Home >Web Front-end >JS Tutorial >How to change the value of a tag in javascript

How to change the value of a tag in javascript

青灯夜游
青灯夜游Original
2021-09-16 17:43:485260browse

Javascript method to change the value of a tag: 1. Use the "document.getElementById('id value')" statement to obtain the a element object based on the specified id value; 2. Use "a element object.innerHTML = "new Text content "" statement to change the value.

How to change the value of a tag in javascript

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

javascript changes the value of a tag

  • ##Get the a tag element object

  • Use the innerHTML attribute to modify the value


Implementation code:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" id="remove">
	</head>

	<body>
		<p style="font-size: 19px; font-weight: bold;">单击按钮改变下面a标签的值</p>
		<a href="#" id="a">超链接文本</a><br /><br />
		<button onClick="Fun()">点击这里</button>
		<script>
			var a = document.getElementById(&#39;a&#39;); //获取a元素对象

			function Fun() {
				a.innerHTML = "新文本内容";
			}
		</script>
	</body>
</html>

Rendering:

How to change the value of a tag in javascript

Description:

The innerHTML attribute sets or returns the HTML between the opening and closing tags. Grammar:

HTMLElementObject.innerHTML=text
HTMLElementObject.innerHTML

[Recommended learning:

javascript advanced tutorial]

The above is the detailed content of How to change the value of a 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