第03章 常规选择器(3)

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');
});

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值