Home >Web Front-end >Front-end Q&A >How to hide li in javascript

How to hide li in javascript

WBOY
WBOYOriginal
2022-03-03 15:30:173866browse

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"".

How to hide li in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

How to hide li with javascript

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:

How to hide li in javascript

After clicking the button:

How to hide li in javascript

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!

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
Previous article:How to use jquery eq()Next article:How to use jquery eq()