Home >Web Front-end >JS Tutorial >How to set element invisible in jquery

How to set element invisible in jquery

藏色散人
藏色散人Original
2021-01-18 10:17:504442browse

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();

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!

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