Home  >  Article  >  Web Front-end  >  How to delete hidden attribute in jquery

How to delete hidden attribute in jquery

青灯夜游
青灯夜游Original
2022-04-27 18:56:162809browse

Methods to delete the hidden attribute: 1. Use removeAttr() to delete the hidden attribute directly, with the syntax "element.removeAttr("hidden")"; 2. Use prop() to set the value of the hidden attribute to empty. Syntax "element.prop("hidden","")".

How to delete hidden attribute in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

HTML hidden attribute

The hidden attribute specifies that the element is hidden. Hidden elements will not be displayed.

If you add this attribute to an element, the element will be hidden.

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	</head>
	<body>
		<p>这是一段可见的段落。</p>
		<p hidden="hidden">这是一段被隐藏的段落,现在显示出来了。</p>
		<p>这是一段可见的段落。</p>
	</body>
</html>

How to delete hidden attribute in jquery

How to delete the hidden attribute in jquery

1. Use removeAttr() to delete the hidden attribute

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(function () {
            $("button").click(function () {
                $("p").removeAttr("hidden");
            })
        })
    </script>
	</head>
	<body>
		<p>这是一段可见的段落。</p>
		<p hidden="hidden">这是一段被隐藏的段落,现在显示出来了。</p>
		<p>这是一段可见的段落。</p>
		<button>删除hidden属性</button>
	</body>
</html>

How to delete hidden attribute in jquery

##2. Use prop() to set the value of the hidden attribute to empty

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(function () {
            $("button").click(function () {
                $("p").prop("hidden","");
            })
        })
    </script>
	</head>
	<body>
		<p>这是一段可见的段落。</p>
		<p hidden="hidden">这是一段被隐藏的段落,现在显示出来了。</p>
		<p>这是一段可见的段落。</p>
		<button>删除hidden属性</button>
	</body>
</html>

How to delete hidden attribute in jquery

[Recommended learning:

jQuery video tutorial, web front-end video

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