webveuje/js/demo/jqchildren.html

58 lines
1.5 KiB
HTML
Raw Normal View History

2021-03-23 10:58:10 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.ancestors *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
.descendants *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
.descendants1 *
{
display: block;
border: 2px solid grey;
color: grey;
padding: 5px;
margin: 15px;
}
.demo2{
color: red;
}
</style>
<script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<div class="descendants" style="width:500px;">div (当前元素)
<p class="11">p (子)
<span>span (孙)</span>
</p>
<p class="11">p (子)
<span>span (孙)</span>
</p>
<p class="22">p (子)
<span>span (孙)</span>
</p>
</div>
<script>
// $(".descendants").children(":first").css({"color":"red","border":"2px solid red"});
// $(".descendants").children(".11").css({"color":"red","border":"2px solid red"});
$(".descendants").child().css({"color":"red","border":"2px solid red"});
</script>
</body>
</html>