Visible (:visible)

Description and Syntax

$(':visible')

selects all elements that are visible.

Examples

  • $('li:visible') selects all <li> elements that are visible
  • $('.myclass:visible') selects all elements with the class myclass that are visible

The following code selects visible div elements.


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from   ww w.j  a  v  a2  s  .co m-->
            $("div:visible").click(function () {
                $(this).css("background", "yellow");
            });
        });
    </script>

  </head>
  <body>
    <body>
      <span></span>
      <div style="display:none;">java2s.com!</div>
      <div>click me</div>


    </body>
</html>

Click to view the demo

The code above generates the following result.

Visible (:visible)