jquery变换字体颜色

利用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>
发布了27 篇原创文章 · 获赞 45 · 访问量 2664

猜你喜欢

转载自blog.csdn.net/weixin_45746635/article/details/102767753