<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="../js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function () {
//为p元素的所有后代span 元素设置为颜色
$("p span").css("color", "blue");
//为p元素的子元素是b的元素设置颜色
$("p>b").css("color", "red");
})
</script>
</head>
<body>
<p><span>aaaa</span><B> <span>TTTTTTTT</span> </B><span>bbbb</span></p>
<p><span>cccc</span></p>
<p><b>RRRR</b><span><b>YYYYYY</b></span><b>PPPPPPPPP</b></p>
</body>
</html>
原文:https://www.cnblogs.com/kukai/p/10915288.html