Home > Article > Web Front-end > How to hide li in javascript
In JavaScript, the display attribute of the style object can be used to hide the li element. The display attribute is used to set the display and hiding of the element. When the attribute value is set to "none", the element will be hidden and not displayed. The syntax is: "li element object.style.display="none"".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
HTML DOM display attribute
How to display the display attribute setting element.
Syntax:
Object.style.display=value
This element will not be displayed when the attribute value is set to none.
The example is as follows:
<html> <head> <script type="text/javascript"> function removeElement() { document.getElementById("li1").style.display="none"; } </script> </head> <body> <h1>示例如下</h1> <li id="li1">点击按钮之后这个li元素就会隐藏</li> <li>点击按钮之后这个li元素不会隐藏</li> <input type="button" onclick="removeElement()" value="隐藏其中一个li元素" /> </body> </html>
Output result:
After clicking the button:
Related recommendations: javascript learning tutorial
The above is the detailed content of How to hide li in javascript. For more information, please follow other related articles on the PHP Chinese website!