Home  >  Article  >  Web Front-end  >  How to hide span elements in jquery

How to hide span elements in jquery

青灯夜游
青灯夜游Original
2022-03-08 11:44:573213browse

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>

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>

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!

Statement:
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