prevAll([selector]) trong jQuery
Miêu tả
Phương thức prevAll([selector]) trong jQuery tìm tất cả phần tử anh em ở trước phần tử hiện tại.
Cú pháp
Sau đây là cú pháp để sử dụng prevAll([selector]) trong jQuery:
selector.prevAll( [selector] )
Tham số
Chi tiết tham số được sử dụng trong phương thức prevAll([selector]) trong jQuery:
selector − Selector tùy ý này để lọc các phần tử ở trước.
Ví dụ
Ví dụ đơn giản sau minh họa cách sử dụng của prevAll([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(){
$("div:last").prevAll().addClass("hilight");
});
</script>
<style>
.hilight { background:yellow; }
</style>
</head>
<body>
<div>first</div>
<div>sibling<div>child</div></div>
<div>sibling</div>
<div>sibling</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(){
$("div:last").prevAll().addClass("hilight");
});
</script>
<style>
.hilight { background:yellow; }
</style>
</head>
<body>
<div class="hilight">first</div>
<div class="hilight">sibling<div>child</div></div>
<div class="hilight">sibling</div>
<div>sibling</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

