Home > Article > Web Front-end > How to hide span elements in jquery
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.
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')
<!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>
<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('display','none'); }); }); </script> //方法4 <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("span").attr('style','display:none'); }); }); </script>
The effect is the same:
[Recommended learning:
jQuery video tutorialThe 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!