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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章