子孫セレクタ(ancestor descendant)



$('p strong')


ソースコード【 HTML 】

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>jQuery 〜</title>
<link rel="stylesheet" href="css/style.css">

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

</head>
<body>
<div>
<p>I have a <strong>pen</strong>.</p>
</div>
<ul>
<li>His <strong>pen</strong> is red.</li>
<li>I need his <strong>pen</strong>.</li>
</ul>
<p>She doesn't need a <strong>pen</strong>.</p>

<script>
$(function(){
	$('div strong').css('background','lightblue');
	$('ul strong').css('background','pink');
});
</script>

</body>
</html>


ブラウザで表示【 Chrome