Home > Article > Web Front-end > How to set element invisible in jquery
Jquery method to set the element to be invisible: 1. Use the "$(selector).hide();" method to set the element to be invisible; 2. Use the "$(selector).show();" method to set it The element is visible, and then use the toggle method to switch the hide and show methods.
The demonstration environment of this tutorial: windows7 system, jquery1.2.6 version, Dell G3 computer.
Recommended: jQuery video tutorial
Jquery method of setting element visibility: You can use the $(selector).hide(); method to set the element to be invisible, use $ The (selector).show(); method sets the element to be visible, and you can use the toggle() method to switch between the hide() and show() methods.
Introduction to jquery's method of setting element visibility:
Display the specified element immediately
$(selector).show();
Hide the specified element immediately
$(selector).hide();
Example:
<!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#hide").click(function(){ $("p").hide(); }); $("#show").click(function(){ $("p").show(); }); }); </script> </head> <body> <p id="p1">如果点击“隐藏”按钮,我就会消失。</p> <button id="hide" type="button">隐藏</button> <button id="show" type="button">显示</button> </body> </html>
You can use the toggle() method to switch the hide() and show() methods.
Show hidden elements and hide displayed elements:
$("button").click(function(){ $("p").toggle(); });
The above is the detailed content of How to set element invisible in jquery. For more information, please follow other related articles on the PHP Chinese website!