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

How to hide a tag in javascript

青灯夜游
Release: 2021-11-03 15:48:07
Original
5553 people have browsed it

JS method to hide a tag: 1. Use the "a tag object.style.display="none"" statement; 2. Use the "a tag object.style.visibility="hidden"" statement; 3 , use the "a label object.style.opacity=0" statement.

How to hide a tag in javascript

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

javascript hides a tag

Method 1: Use the display attribute

<a href="#" id="a">a标签超链接</a><br /><br />
<input type="button" value="点击按钮进行隐藏" id="btn" />
<script>
	function my(id) {
		return document.getElementById(id);
	}
	my("btn").onclick = function() {
		my("a").style.display = "none";
	}
</script>
Copy after login

Rendering:

How to hide a tag in javascript

Method 2: Using the visibility attribute

<a href="#" id="a">a标签超链接</a><br /><br />
<input type="button" value="点击按钮进行隐藏" id="btn" />
<script>
	function my(id) {
		return document.getElementById(id);
	}
	my("btn").onclick = function() {
		my("a").style.visibility="hidden";
	}
</script>
Copy after login

Rendering:

How to hide a tag in javascript

Method 3: Using the opacity attribute

<a href="#" id="a">a标签超链接</a><br /><br />
<input type="button" value="点击按钮进行隐藏" id="btn" />
<script>
	function my(id) {
		return document.getElementById(id);
	}
	my("btn").onclick = function() {
		my("a").style.opacity=0;
	}
</script>
Copy after login

Rendering:

How to hide a tag in javascript

[Recommended learning: javascript Advanced Tutorial

The above is the detailed content of How to hide 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!