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

青灯夜游
Release: 2023-01-11 09:20:38
Original
5258 people have browsed it

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

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

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

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