jQuery :visible Selector

jQueryWeb DevelopmentFront End Technology

The :visible selector in jQuery is used to select elements that are currently visible.

Syntax

The syntax is as follows −

$(":visible")

Example

Let us now see an example to implement the jQuery :visible selector −

<!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("color", "red");
   });
</script>
</head>
<body>
<h1>Heading One</h1>
<h2>Heading Two</h2>
<p style="display:none">Demo text 1...</p>
<p>Demo text 2...</p>
<p style="display:none">Demo text 3...</p>
<p>Demo text 4...</p>
</body>
</html>

Output

This will produce the following output −

raja
Published on 11-Nov-2019 11:36:48
Advertisements