jQuery Tutorial – Hiding an Element

Following our jQuery download tutorial, we have created a simple tutorial on how to hide an element on a webpage. The video tutorial can be viewed next, and the step by step guide below.

  1. Create a new folder in your documents containing the latest jQuery file.
  2. Create a new HTML document in the same folder as the jquery file.
  3. Open the HTML document in a text editor and add in the following code;


    <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
    “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
    <html>
    <head>
    <title>jQuery Example</title>
    <script type=”text/javascript” src=”jquery-1.7.1.min.js”></script>
    <script type=”text/javascript”>
    $(document).ready(function(){
    $(“#clickMe”).click(function(){
    $(this).hide();
    });
    });
    </script>
    </head>
    <body>
    <p id=”clickMe”>Click me and I will disappear!</p>
    <p>I will not disappear.</p>
    </body>
    </html>

    The code highlighted in red are the elements which have been added in for this jQuery example to work.

    The element in the body with the id=”clickMe” will follow the rules set in the header script, where as the other will just display as normal.

  4. Save changes to the HTML document
  5. Open the HTML document in a browser to view the working webpage

Click on the top line and watch it disappear
Click on the remaining line – it shouldn’t budge!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>