Home > Web Front-end > JS Tutorial > body text

How to remove meta tag in javascript

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

Methods to delete meta tags: 1. Use the removeChild() method to delete, the syntax is "meta element object.parentNode.removeChild(meta element object)"; 2. Use the remove() method to delete, the syntax is "meta element Object.remove()".

How to remove meta tag in javascript

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

Method 1. Use the removeChild() method to delete the meta tag element

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

	<body style="text-align:center;">
		<p style="font-size: 19px; font-weight: bold;">单击按钮删除meta元素</p>
		<button onClick="Fun()">点击这里</button>

		<p id="DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p>

		<!-- Script to remove HTML element -->
		<script>
			var down = document.getElementById(&#39;DOWN&#39;);
			var meta = document.getElementById(&#39;remove&#39;); //获取meta标签元素对象

			function Fun() {
				meta.parentNode.removeChild(meta);
				down.innerHTML = "元素被删除!";
			}
		</script>
	</body>
</html>
Copy after login

Rendering:

How to remove meta tag in javascript

Method 2. Use the remove() method to delete the meta tag element from the document

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

	<body style="text-align:center;">
		<p style="font-size: 19px; font-weight: bold;">单击按钮删除meta元素</p>
		<button onClick="Fun()">点击这里</button>

		<p id="DOWN" style="color: red; font-size: 24px; font-weight: bold;"> </p>

		<!-- Script to remove HTML element -->
		<script>
			var down = document.getElementById(&#39;DOWN&#39;);
			var meta = document.getElementById(&#39;remove&#39;); //获取meta标签元素对象

			function Fun() {
				meta.remove();
				down.innerHTML = "meta元素被删除!";
			}
		</script>
	</body>
</html>
Copy after login

Rendering:

How to remove meta tag in javascript

[Recommended Study: javascript advanced tutorial

The above is the detailed content of How to remove meta 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