:visible Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:visible

Description

The :visible selector selects elements that are currently visible.

Visible elements are elements that are not:

  • elements set to display:none
  • Form elements with type="hidden"
  • Width and height set to 0

The following code shows how to select all visible <p> elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p:visible").css("background-color", "yellow");
});// w w w. jav a2s .co m
</script>
</head>
<body>
<p style="display:none">This is a hidden paragraph.</p>
<h1>This is a heading</h1>
<p style="display:none">This is a hidden paragraph.</p>
<p>This is a pargraph.</p>
<p>This is another paragraph.</p>
<p style="display:none">This is a hidden paragraph.</p>

</body>
</html>

Related Tutorials