Home > Web Front-end > Front-end Q&A > What are the codes for hiding elements in jquery

What are the codes for hiding elements in jquery

青灯夜游
Release: 2022-03-22 20:25:04
Original
4096 people have browsed it

jquery hidden element code: 1. "Specify element object.hide();"; 2. "Specify element object.toggle(1000);"; 3. "Specify element object.slideDown(); "; 4. "Specify element object.css("display", "none")".

What are the codes for hiding elements in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Many ways to hide elements in jquery:

1. Use hide()

hide() can hide visible elements:

$("button").click(function(){
  $("p").hide();
});
Copy after login

hide() is often used together with show to switch between visible and hidden elements.

show() can display hidden elements.

$("button").click(function(){
  $("p").show();
});
Copy after login

2. Use the toggle() method

toggle() method to switch the visible state of the element.

If the selected elements are visible, then hide these elements. If the selected elements are hidden, then display these elements.

$("button").click(function(){
  $("p").toggle(1000);
});
Copy after login

3. Use the slideDown() method

Show hidden elements in a sliding manner

$("button"").click(function(){
  $("p").slideDown();
});
Copy after login

4. Use the css() method

Use the css() method to set the displays style to hide visible elements:

$("button"").click(function(){
  $("p").css("display","none");
  //
});
Copy after login

[Recommended learning: jQuery video tutorial, web front-end video

The above is the detailed content of What are the codes for hiding elements 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