Home >Web Front-end >JS Tutorial >How jquery controls the display and hiding of li elements

How jquery controls the display and hiding of li elements

WBOY
WBOYOriginal
2021-11-30 19:23:174732browse

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)

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

$(selector).show(speed,callback)

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>

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!

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