Home  >  Article  >  Web Front-end  >  How to implement click text to trigger click event in jquery

How to implement click text to trigger click event in jquery

青灯夜游
青灯夜游Original
2022-04-28 15:00:153372browse

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(){...})".

How to implement click text to trigger click event in jquery

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>

How to implement click text to trigger click event in jquery

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>

How to implement click text to trigger click event in jquery

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn