jQuery click() Method

 

Click event occurs when you clicked on the selected element and it execute the click method.

Syntax : $(selection).click();

Example : Get the content of p tag and show under alert message with click event.

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://code.jquery.com/jquery-3.5.0.min.js"></script> <script> $(document).ready(function() { $("p").click(function() { alert($("p").text()); }); }); </script> </head> <body> <!–– Change the text in p tag and click on run it to see the output --> <p>Click me to see the "APPWRK IT Solutions" in alert box</p> </body> </html>
Output