not(selector) trong jQuery
Miêu tả
Phương thức not(selector) trong jQuery gỡ bỏ tất cả các phần tử so khớp với selector đã cho từ tập hợp các phần tử được so khớp.
Cú pháp
Sau đây là cú pháp để sử dụng not(selector) trong jQuery:
selector.not( selector )
Tham số
Chi tiết tham số được sử dụng trong phương thức not(selector) trong jQuery:
selector − Nó có thể là một danh sách các selector phân biệt bởi dấu phảy để áp dụng nhiều bộ lọc cùng lúc (ví dụ: not(".class1, .class2")).
Ví dụ
Ví dụ đơn giản sau minh họa cách sử dụng của not(selector) trong jQuery.
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("li").not(".middle").addClass("selected");
});
</script>
<style>
.selected { color:red; }
</style>
</head>
<body>
<div>
<ul>
<li class="top">list item 1</li>
<li class="top">list item 2</li>
<li class="middle">list item 3</li>
<li class="middle">list item 4</li>
<li class="bottom">list item 5</li>
<li class="bottom">list item 6</li>
</ul>
</div>
</body>
</html>
Nó sẽ cho kết quả:
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("li").not(".middle").addClass("selected");
});
</script>
<style>
.selected { color:red; }
</style>
</head>
<body>
<div>
<ul>
<li class="selected">list item 1</li>
<li class="selected">list item 2</li>
<li class="middle">list item 3</li>
<li class="middle">list item 4</li>
<li class="selected">list item 5</li>
<li class="selected">list item 6</li>
</ul>
</div>
</body>
</html>
Nó sẽ cho kết quả:
Công cụ giáo viên (2048.VN)
Tạo- trộn đề thi miễn phí từ file PDF, Word, Giao bài nhanh chóng, Hoàn toàn Free
Các bài học jQuery khác tại VietJack:
Dành cho bạn
Công cụ giáo viên
- Tạo đề online từ PDF / Word
- Trộn nhiều mã đề, in Offline
- Giao bài online, Quản lí lớp học

