English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Methods to modify the content of html elements and attributes with JS functions

Modify Element Content:

<body>
	<p id="pid">Hello</p>
	<button onclick="demo()">Button</button>
	<script>
		function demo(){
			var nv = document.getElementById("pid");
			nv.innerHTML="World";
		}
	</script>
</body>

Modify Element Tag Attributes:

<body>
	<a href="http://www.baidu.com/" id="aid" >Haha</a>
	<button onclick="demo()">Button</button>
	<script>
		function demo(){
			document.getElementById("aid").href="http://www.jikexueyuan.com";
		}
	</script>
</body>

This is the full content of the method to modify the element content of the JS function and modify the attribute content, I hope everyone will support and cheer for the tutorial website~

You May Also Like