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

How to delete the hidden attribute of an element in javascript

青灯夜游
Release: 2022-01-12 12:08:53
Original
6423 people have browsed it

In JavaScript, you can use the removeAttribute() method to delete the hidden attribute of an element. The function of this method is to delete the specified attribute. The syntax is "element.removeAttribute("Attribute Name")".

How to delete the hidden attribute of an element in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

The hidden attribute is a Boolean attribute.

If this attribute is set, it specifies that the element is still or no longer relevant.

Browsers should not display elements that have the hidden attribute specified.

The hidden attribute can also be used to prevent the user from viewing an element until certain conditions are matched (such as a checkbox being selected). JavaScript can then remove the hidden attribute to make this element visible.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是一段可见的段落。</p>
<p hidden="hidden">这是一段隐藏的段落。</p>
<p>这是一段可见的段落。</p>
</body>
</html>
Copy after login

How to delete the hidden attribute of an element in javascript

So how to delete the hidden attribute of an element using javascript?

In JavaScript, use the element's removeAttribute() method to remove a specified attribute. The usage is as follows:

element.removeAttribute(attributename)
Copy after login
  • Parameters attributename: Indicates the attribute name of the element.

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	</head>
	<body>
		<p>这是一段可见的段落。</p>
		<p id="hid" hidden="hidden">这是一段隐藏的段落。</p>
		<p>这是一段可见的段落。</p>
		<button id="btn">删除hidden属性</button>
		<script>
			function my(id) {
				return document.getElementById(id);
			}
			my("btn").onclick = function() {
				my("hid").removeAttribute("hidden"); 
			}
		</script>
	</body>
</html>
Copy after login

How to delete the hidden attribute of an element in javascript

[Related recommendations: javascript learning tutorial]

The above is the detailed content of How to delete the hidden attribute of an element in javascript. 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