Love beautiful code? We do too.
Đã được thêm vào từ phiên bản 1.2
.nextAll()
$('p').nextAll();
.nextAll('Bộ chọn')
$('p').nextAll('.test');
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('li.second').nextAll().css('background-color','yellow');
});
</script>
</head>
<body>
<ul>
<li>li thứ nhất</li>
<li class="second">li thứ hai</li>
<li>li thứ ba</li>
<li>li thứ tư</li>
<li>li thứ năm</li>
</ul>
</body>
</html>
Hiển thị trình duyệt:
Ta thấy tất cả các thành phần li cùng cấp ngay sau thành phần li sử dụng .nextAll() đã được thêm background-color.
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('li').nextAll('.test').css('background-color','yellow');
});
</script>
</head>
<body>
<ul>
<li>li thứ nhất</li>
<li>li thứ hai</li>
<li>li thứ ba</li>
<li class="test">li thứ tư</li>
<li>li thứ năm</li>
</ul>
</body>
</html>
Hiển thị trình duyệt:
Với cách sử dụng .nextAll('.test') ta đã xác định cụ thể thành phần có class="test" ngay sau thành phần
Hoclaptrinh.vn © 2017
From Coder With
Unpublished comment
Viết câu trả lời