jQuery DOM操作(css类)

html代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>DOM操作CSS类</title>
        <script src="js/jquery-3.7.1.js"></script>
        <style>
             body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f4f4f9;
            flex-direction: column;
        }

        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        h1 {
            margin-bottom: 20px;
        }

        button {
            padding: 10px 20px;
            margin: 5px;
            border: none;
            border-radius: 5px;
            background-color: #007BFF;
            color: white;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #0056b3;
        }

       .highlight {
            background-color: pink;
        }

       .large {
            font-size: 24px;
        }
        </style>
    </head>
    <body>
        <div class="container">
            <h1 id="title">吼吼哈嘿</h1>
            <div>
                <button id="add-class">添加类</button>
                <button id="remove-class">移除类</button>
                <button id="toggle-class">切换类</button>
                <button id="change-css">设置</button>
            </div>
        </div>
        <script>
            //add-class
            $("#add-class").click(function(){
                $("#title").addClass("highlight large");
            });
            $("#remove-class").click(function(){
                $("#title").removeClass("highlight large");
            });
            $("#toggle-class").click(function(){
                $("#title").toggleClass("highlight large");
            });
            $("#change-css").click(function(){
                $("#title").css({
                    "color":"pink",
                    "font-weight":"bold"
                });
            });
        </script>
    </body>
</html>

---------------------------------------------------------------------------------------------------------------------------------

呈现的效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值