Home > Web Front-end > Front-end Q&A > How to hide span elements in jquery

How to hide span elements in jquery

青灯夜游
Release: 2022-03-08 11:44:57
Original
3271 people have browsed it

Hide method: 1. Use the "$("span").hide();" statement to hide; 2. Use the "$("span").toggle(false);" statement to hide; 3. Use the "$("span").css('display','none');" statement to hide it.

How to hide span elements in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

jquery hides span elements

In jquery, there are many ways to hide span elements.

  • hide()

  • ##toggle(false)

  • css('display','none')

  • ##attr('style','display:none')

  • Example:

<!DOCTYPE html>
<html>
	<head>
	</head>
	<body>
		<h1>这是一个标题</h1>
		<span style="font-size:120%;color:red">这是一个span元素。</span>
		<p>这是一个p元素。</p>
		<button>隐藏span元素</button>
	</body>
</html>
Copy after login

jq code:

<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>

//方法1
<script type="text/javascript">
	$(document).ready(function(){
	  $("button").click(function(){
	  $("span").hide();
	  });
	});
</script>

//方法2
<script type="text/javascript">
	$(document).ready(function(){
	  $("button").click(function(){
	  $("span").toggle(false);
	  });
	});
</script>


//方法3
<script type="text/javascript">
	$(document).ready(function(){
	  $("button").click(function(){
	  $("span").css(&#39;display&#39;,&#39;none&#39;);
	  });
	});
</script>


//方法4
<script type="text/javascript">
	$(document).ready(function(){
	  $("button").click(function(){
	  $("span").attr(&#39;style&#39;,&#39;display:none&#39;);
	  });
	});
</script>
Copy after login

The effect is the same:

How to hide span elements in jquery[Recommended learning:

jQuery video tutorial

, web front-end video]

The above is the detailed content of How to hide span elements in jquery. 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