Home > Article > Web Front-end > How to implement click text to trigger click event in jquery
Implementation method: 1. Use click() to bind the click event to the text element and set the processing function, the syntax is "element.click(function(){...})"; 2. Use on( ) Bind click events to text elements, the syntax is "element.on("click", function(){...})".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery method to implement click text and trigger click events
1. Use click()
Use click() to bind click events to text elements and set event processing functions
Syntax:
$(selector).click(function(){...})
Example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("p").click(function() { $("p").css("color","pink"); }); }); </script> </head> <body> <p>点击这个文字段落。</p> </body> </html>
2. Use on()
Use on() to bind click events to text elements and set the event processing function
Syntax :
$(selector).on("click",function(){...})
Example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("p").on("click",function(){ $("p").css("background-color","pink"); }); }); </script> </head> <body> <p>点击这个文字段落。</p> </body> </html>
[Recommended learning: jQuery video tutorial, web front-end video】
The above is the detailed content of How to implement click text to trigger click event in jquery. For more information, please follow other related articles on the PHP Chinese website!