In jquery, you can use the ":visible" selector and is() method to determine whether an element is displayed. The syntax is "element object.is(':visible')". You can check whether the specified element is displayed. Matches the ":visible" selector, that is, whether it is a visible element; if the element is displayed, it returns true.

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, you can use the ":visible" selector and is() method to determine whether an element is displayed
is() method is used to view the selected Whether the element matches the selector.
-
: The visible selector selects each element that is currently visible.
Elements other than the following situations are visible elements:
is set to display:none
with Form elements with type="hidden"
width and height set to 0
hidden parent elements (this will also hide child elements )
Syntax to determine whether an element is displayed:
元素對(duì)象.is(':visible')
Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$(function () {
$("button").click(function () {
var node=$('span');
if(node.is(':visible')){
alert("顯示元素");
}else{
alert("隱藏元素,將它顯示出來(lái)");
node.show();
}
})
})
</script>
</head>
<body>
<div>這是一段可見(jiàn)的div內(nèi)容。</div>
<span hidden="hidden">這是一個(gè)被隱藏的內(nèi)容,現(xiàn)在顯示出來(lái)了。</span>
<p>這是一段可見(jiàn)的內(nèi)容。</p>
<button>判斷span元素是否顯示</button>
</body>
</html>

[Recommended learning: jQuery video tutorial, web front-end video】
The above is the detailed content of How to determine whether an element is displayed in jquery. For more information, please follow other related articles on the PHP Chinese website!