jQuery 子要素を検索して操作するサンプル
環境
Google Chrome 105.0.5195.127
Windows 10 Home 64bit
jquery 3.6.0
構文
要素.find( selector/要素 )
指定の要素から子孫要素を検索できます。
使用例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btnchk").click(function () {
$(".cft").find(".p1").css("background-color", "green");
});
});
</script>
</head>
<body>
<div class="cft">
<p>123</p>
<p class="p1">ttss</p>
</div>
<input type="button" id="btnchk" value="検証" />
</body>
</html>
実行結果
「検証」ボタンを押すと、div要素「」cftの子クラス文字の背景色がgreenになります。