jQuery > Events

Click event in jQuery

How to attach a click event to a html element in jQuery?

To attach a click event to an element, click() method can be used that fires when the element is clicked.

       $("#btnClick").click(function () {
           alert("click event called");

Above code snippet first find html element whose id is "btnClick" and attach "click" event. When this element is clicked, a function fires that shows "click event called" message in the JavaScript alert box.

 Views: 999 | Post Order: 62

Write for us