hide() and show()
With jQuery, you can use the hide() and show() methods to hide and show HTML elements:
Syntax:
$(selector).hide(speed,callback);
$(selector).show(speed,callback);
The optional speed parameter specifies hiding / Display speed, which can take the following values: "slow", "fast" or milliseconds.
The optional callback parameter is the name of the function to be executed after hiding or displaying is completed.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").hide(1000); }); }); </script> </head> <body> <button>隐藏</button> <p>这是第一个</p> <p>这是第二个</p> </body> </html>
jQuery toggle()
With jQuery, you can use the toggle() method to toggle the hide() and show() methods.
Show hidden elements and hide displayed elements:
Syntax:
$(selector).toggle(speed,callback);
The optional speed parameter specifies the speed of hiding/showing, which can take the following values: "slow", "fast" or milliseconds.
The optional callback parameter is the name of the function executed after the toggle() method is completed.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").toggle(); }); }); </script> </head> <body> <button>隐藏/显示</button> <p>点击一次隐藏</p> <p>再点击一次显示</p> </body> </html>