jQuery Selector :visible

Introduction

The :visible selector selects every element that is currently visible.

Visible elements are elements that are not:

  • display:none
  • Form elements with type="hidden"
  • Width and height set to 0
  • A hidden parent element
$(":visible")

Select all visible <p> elements:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("p:visible").css("background-color", "yellow");
});/*from  w ww .j  a va2s . co  m*/
</script>
</head>
<body>

<h1>This is a heading</h1>

<p>This is a pargraph.</p>
<p>This is another paragraph.</p>
<p style="display:none">This is a hidden paragraph.</p>

</body>
</html>



PreviousNext

Related