Did you find this useful?
Socialize it today.


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.

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Professional jQuery Pro jQuery JavaScript and jQuery: The Missing Manual