{"name":"click","type":"method","title":".click()","deprecated":null,"removed":null,"desc":"Bind an event handler to the \"click\" JavaScript event, or trigger that event on an element.","categories":["events/mouse-events","version/1.0","version/1.4.3"],"entries":[{"return":"jQuery","signatures":[{"added":"1.0","argument":{"desc":"A function to execute each time the event is triggered.","name":"handler(eventObject)","type":"Function"}},{"added":"1.4.3","argument":[{"desc":"An object containing data that will be passed to the event handler.","name":"eventData","type":"Object","optional":"true"},{"desc":"A function to execute each time the event is triggered.","name":"handler(eventObject)","type":"Function"}]},{"added":"1.0"}],"examples":[{"desc":"Hide paragraphs on a page when they are clicked:","code":"\n$( \"p\" ).click(function() {\n $( this ).slideUp();\n});\n","css":"\n p {\n color: red;\n margin: 5px;\n cursor: pointer;\n }\n p:hover {\n background: yellow;\n }\n","html":"\n
First Paragraph
\nSecond Paragraph
\nYet one more Paragraph
\n"},{"desc":"Trigger the click event on all of the paragraphs on the page:","code":"\n$( \"p\" ).click();\n"}],"longdesc":"\nThis method is a shortcut for .on( \"click\", handler ) in the first two variations, and .trigger( \"click\" ) in the third.\n The click event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed and released. Any HTML element can receive this event.\n For example, consider the HTML:
\n<div id=\"target\">\n Click here\n</div>\n<div id=\"other\">\n Trigger the handler\n</div>\n \n \n
\n
The event handler can be bound to any <div>:
\n$( \"#target\" ).click(function() {\n alert( \"Handler for .click() called.\" );\n});\n \n Now if we click on this element, the alert is displayed:
\n\n Handler for .click() called.\n
\nWe can also trigger the event when a different element is clicked:
\n\n$( \"#other\" ).click(function() {\n $( \"#target\" ).click();\n});\n \n After this code executes, clicking on Trigger the handler will also alert the message.
\nThe click event is only triggered after this exact series of events:
This is usually the desired sequence before taking an action. If this is not required, the mousedown or mouseup event may be more suitable.