利用jquery中的選擇器,至少寫三種方法,讓p元素的字體顏色變成紅色
用了三種選擇器
圖片:
下面是代碼:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="jquery.js"></script>
<style>
div{
width: 200px;
height: 200px;
background-color: chartreuse;
}
</style>
</head>
<body>
<center>
<h2>利用jquery中的選擇器,至少寫三種方法,讓p元素的字體顏色變成紅色 </h2>
<div>
<p>11111</p>
<p id="two">22222</p>
<p class="three">33333</p>
</div>
</center>
<script>
$(function () {
$("div p:first-child").on("click",function () {
$(this).css("color","red");
});
$("#two").on("click",function () {
$(this).css("color","blue");
});
$(".three").on("click",function () {
$(this).css("color","green");
});
});
</script>
</body>
</html>