.andSelf()

andSelf(): Thêm hành động cho chính thành phần chọn ban đầu.

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>andSelf() Demo</title>
	<link rel="stylesheet" href="">
	<style type="text/css" media="screen">
		p, div {
			margin: 5px;
			padding: 5px;
		}
		.border{
			border: 2px solid red;
		}
		.brackground{
			background: yellow;
		}
		.left, .right{
			width: 45%;
			float:left;
		}
		.right{
			margin-left: 3%;
		}
	</style>
	<script type="text/javascript" src="jquery-2.2.4.min.js"></script>
</head>
<body>
	<div class="left">
		<p><strong>Before<code>andSelf()</code></strong></p>
		<div class="before-andself">
			<p>First Paragraph</p>
			<p>Second Paragraph</p>
		</div>
	</div>
	<div class="right">
		<p><strong>After <code>andSelf()</code></strong></p>
		<div class="after-andself">
			<p>First Paragraph</p>
			<p>Second Paragraph</p>
		</div>
	</div>
	<script>
		$("div.left, div.right").find('div, div > p').addClass('border');

		//First Example
		$("div.before-andself").find('p').addClass("brackground");

		//Second Example
		$("div.after-andself").find("p").andSelf().addClass("brackground");

	</script>
</body>
</html>

Kết quả:

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Chào mừng bạn đến với blog của tôi! Đây là nơi tôi chia sẻ những trải nghiệm, suy nghĩ và kiến thức mà tôi học được trong cuộc sống và công việc. Hy vọng bạn sẽ tìm thấy điều gì đó hữu ích và thú vị tại đây.

Design a site like this with WordPress.com
Get started