index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>常规选择器</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="demo.js"></script>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<!--
<div id="box">
<p>p</p>
<p>p</p>
<p>p</p>
<div>
<p>p</p>
<p>p</p>
<p>p</p>
</div>
</div>
<p>p</p>
<p>p</p>
<p>p</p>
<div id="box">div</div>
<span>span</span>
<p>p</p>
<p>p</p>
<p>p</p>
-->
<strong>strong</strong>
<strong>strong</strong>
<strong>strong</strong>
<p>p</p>
<strong>strong</strong>
<strong>strong</strong>
<strong>strong</strong>
<div id="box">div</div>
<strong>strong</strong>
<strong>strong</strong>
<strong>strong</strong>
<p>p</p>
<strong>strong</strong>
<strong>strong</strong>
<strong>strong</strong>
</body>
</html>
style.css
/* CSS Document */
/*
#box > p{ color:#c00;}
div + p{ color:#c00;}
#box ~p{ color:#c00;}
*/
demo.js
$(function(){
//$('#box p').css('color','red');
//find
//$('#box').find('p').css('color','red');
//$('#box > p').css('color','red');
//$('#box').children('p').css('color','#f60');
//$('div + p').css('color','red');
//next() 方法
//$('div').next('p').css('color','#f60');
//$('#box ~p').css('color','red');
//$('#box').nextAll('p').css('color','#f60');
//$('div').next().css('color','#f60');
//$('div').next('*').css('color','#f60');//next()等选择器方法不传参,就相当于传递了 * 号
//如果 * 在某个环境里有所浪费,建议尽量不去使用
//prev
//$('#box').prev('p').css('color','#f60');
//prevAll
//$('#box').prevAll('p').css('color','#f60');
//$('#box').nextAll('p').css('color','#f60');
//$('#box').prevAll('p').nextAll('p').css('color','#f60');//错误形式
//siblings 上下同级所有
//$('#box').siblings('p').css('color','#f60');
//nextUntil()方法 同级下非指定元素选定,遇到则停止
$('#box').nextUntil('p').css('color','#f60');
//prevUntil()方法 同级上非指定元素选定,遇到则停止
$('#box').prevUntil('p').css('color','#f60');
});