Home > Web Front-end > JS Tutorial > body text

How to set element invisible in jquery

藏色散人
Release: 2022-12-30 11:11:59
Original
4392 people have browsed it

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.

How to set element invisible in jquery

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();
Copy after login

Hide the specified element immediately

$(selector).hide();
Copy after login

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>
Copy after login

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();
});
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!