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

How jquery controls the display and hiding of li elements

WBOY
Release: 2021-11-30 19:23:17
Original
4701 people have browsed it

How jquery controls the display and hiding of li elements: 1. Use the show() method to control the display of li elements. The syntax is "$("li").show()"; 2. Use hide( ) method controls the hiding of li elements, and the syntax is "$("li").hide()".

How jquery controls the display and hiding of li elements

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

How does jquery control the display and hiding of li

In jquery, you can control li through the show() method and hide() method For display and hiding, the hide() method hides the selected element if it has been displayed. The syntax is:

$(selector).hide(speed,callback)
Copy after login

show() method. If the selected elements have been hidden, these elements are displayed. The syntax is:

$(selector).show(speed,callback)
Copy after login

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
</head>
<body>
<ul>
  <li id="test">雪碧</li>
  <li>可乐</li>
  <li>凉茶</li>
</ul>
<button id="anniu">显示与隐藏</button>
<script>
$(function(){
$(&#39;#anniu&#39;).click(function(){//点击按钮
if($(&#39;#test&#39;).is(&#39;:hidden&#39;)){//如果当前隐藏
$(&#39;#test&#39;).show();//点击显示
}else{//否则
$(&#39;#test&#39;).hide();//点击隐藏
}
})
})
</script>
</body>
</html>
Copy after login

Output result:

How jquery controls the display and hiding of li elements

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How jquery controls the display and hiding of li elements. 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