jQuery Selector How to - Select visible divs








Question

We would like to know how to select visible divs.

Answer


<!--  www.j  av a 2 s  .c  om-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("div:visible").click(function () {
                $(this).css("background", "yellow");
            });
        });
    </script>
  </head>
  <body>
      <span></span>
      <div style="display:none;">Hider!</div>
      <div>click me</div>
  </body>
</html>

The code above is rendered as follows: