DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>jQuery层次选择器title>
head>
<body>
<p>p>
<div id="father">
<div>
<span>span1span>
<span>span2span>
<span>span3span>
div>
<div>
<b>1b>
<div>div1div>
<div>div2div>
<div>div3div>
<p>p>
div>
<div>div>
<p>p>
<p>p>
<p>p>
<span>sss1span>
div>
body>
html>
<script src="jquery-1.12.4.js">script>
<script>
$(function () {
//需求1:获取id为father这个元素的所有子div.
// console.log($('#father > div'));
//需求2:获取id为father这个元素的所有子div以及所有子p.
// console.log($('#father > div, p'));
// console.log($('#father > div, #father > p'));
//需求3:获取id为father这个div的所有后代div.
// console.log($('#father div'));
//需求4:获取id为father这个div的所有后代div,以及id为father这个div的所有后代span.
// console.log($('#father div, #father div span')); // 错误, 显示9个
console.log($('#father div, #father span')); // 显示 10个
/**
* jQuery层级选择器
* 子代选择器: $('ul > li')
* 藕带选择器: $('ul li'); // 包括孙子
*/
});
script>
