How to run a code on click event in jQuery ? Last Updated : 06 Jun, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will see how to run the code after clicking on an event. To run the code after clicking an event, we use the click() method. The click() method is used to run the code when a click event occurs. The click() method to attach a click event handler to selected elements. Inside the handler function, you can define the code to be executed when the click event occurs, such as manipulating the DOM, making AJAX requests, or performing other operations. Syntax: $(selector).click(function); Parameter: It accepts an optional parameter “function” which is used to run when a click event occurs. Example: In This example, we are using the above-explained method. HTML <!DOCTYpe html> <html> <head> <title> How to run a code on click event in jQuery? </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <!-- jQuery code to show the working of this method --> <script> $(document).ready(function () { $("body").css("text-align", "center"); $("h1").css("color", "green"); $("p").click(function () { $(this).css("font-size", "20px"); $(this).css("color", "green"); }); }); </script> </head> <body> <h1>GeeksforGeeks</h1> <h3> How to run a code on click event in jQuery? </h3> <p onclick="alert('paragraph was clicked')"> GeeksforGeeks: A computer science portal </p> </body> </html> Output: click event Comment More infoAdvertise with us Next Article How to add dbclick() on right click in jQuery? V vkash8574 Follow Improve Article Tags : Web Technologies JQuery Web technologies HTML-Tags CSS-Properties jQuery-Questions jQuery +3 More Similar Reads How to run a code on double-click event in jQuery ? In this article, we will see how to run a code after double clicked the element using jQuery. To run the code on double clicked we use dblclick() method. This method is used to trigger the double-click event to occur. This method occurs when the selected element will be double clicked. Syntax: $(sel 1 min read How to run a code on hover event in jQuery ? In this article, we will see how to change the style of elements on hover event using jQuery. To change the style of hover event, hover() method is used. The hover() method is used to specify two functions to start when the mouse pointer moves over the selected element. Syntax: $(selector).hover(Fun 1 min read How to run a code on mouseenter event in jQuery ? In this article, we will see how to run the code when the mouse enters into the specific area using jQuery. To run the code on a mouse enter a specific area, mouseenter() method is used. The mouseenter() method works when the mouse pointer moves over the selected element. Syntax: $(selector).mouseen 1 min read How to run a code on document ready event in jQuery ? In this article, we will see how to run a code when a page loads using jQuery. To run a code at page load time, we will use the ready() method. This method helps to load the whole page and then execute the rest code. This method specifies the function to execute when the DOM is fully loaded. Syntax: 1 min read How to add dbclick() on right click in jQuery? The jQuery dblclick() method is used to detect whenever a particular element is double-clicked. This method only detects left mouse button double clicks and not the right mouse button double clicks. In this article, we will see how to simulate the double right mouse click in jQuery. Approach: There 3 min read How to run the code on change event using jQuery ? In this article, we will see how to run the code on change events using jQuery. The change event is used to trigger when the user changes the value of the element. Syntax: $(selector).change(function) Example: In the below example, we are creating a textarea element that contains GeeksforGeeks text. 1 min read Like