jQuery HTML Element How to - Hide paragraphs when they are clicked








Question

We would like to know how to hide paragraphs when they are clicked.

Answer


<!--from   w  w  w .  jav  a 2  s .c o m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("p").click(function () { 
              $(this).slideUp(); 
            });
            $("p").hover(function () {
              $(this).addClass("hilite");
            }, function () {
              $(this).removeClass("hilite");
            });

        });
    </script>
  </head>
  <body>
          <p>First</p>
          <p>Second</p>
          <p>3</p>
  </body>
</html>

The code above is rendered as follows: