利用jquery中的选择器,至少写三种方法,让p元素的字体颜色变成红色
1.效果图
2.代码
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/jquery.js"></script>
<style>
div{
width: 100px;
height: 100px;
background-color: chocolate;
}
</style>
</head>
<body>
<h2>利用jquery中的选择器,至少写三种方法,让p元素的字体颜色变成红色 </h2>
<div>
<p>11111</p>
<p id="two">22222</p>
<p class="three">33333</p>
</div>
<script>
$(function () {
$("div p:first-child").on("click",function () {
$(this).css("color","red");
});
$("#two").on("click",function () {
$(this).css("color","yellow");
});
$(".three").on("click",function () {
$(this).css("color","green");
});
});
</script>
</body>
</html>