jQuery Click Event

Saturday, June 16, 2012

The jQuery event click() method is triggered when an element is clicked. The click() method triggers the click event, or specifies a function to run when a click event occurs.


Syntax

$(selector).click()
$(selector).click(function)


ParameterDescription
functionOptional. Function to run when the event occurs


Basic Example

In the jQuery code listed above, the click() method specifies that a function should run when the click event occurs. In the example below, the div element will be hidden once it is clicked. Try it yourself, by clicking anywhere within the div element.


    <script type="text/javascript" src="jquery.js">
       </script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("div.#hideMe").click(function () {
                $("div.#hideMe").hide();
            });
        });
    </script>


Click anywhere inside of this div element.

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

HTML CSS and JavaScript Editor Professional jQuery JavaScript and jQuery: The Missing Manual