亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery attributes and styles (4)

By dynamically changing the class name (class), you can modify the elements to show different effects. In the HTML structure, multiple classes are separated by spaces. When a node (or a label) contains multiple classes, the className attribute of the DOM element response does not obtain an array of class names, but a string containing spaces. , which makes multi-class operations very troublesome. The same jQuery developer also considered this situation and added an .addClass() method for dynamically adding class names

addClass( className ) method

Look at the following code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
    <style type="text/css">
        div{
            width:200px;
            height:200px;
        }
        .bg{
            background:red;
        }
    </style>
</head>
<body>
    <div id="div">php 中文網(wǎng)</div>

    <script type="text/javascript">
        $("#div").addClass('bg');
    </script>
</body>
</html>


removeClass() Remove style

The following case:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
    <style type="text/css">
        .div{
            width:200px;
            height:200px;
            background:red;
        }
    </style>
</head>
<body>
    <div class="div">php 中文網(wǎng)</div>

    <script type="text/javascript">
        $(".div").removeClass("div");
    </script>
</body>
</html>

The above code, so that the style of our div is deleted


Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> <style type="text/css"> div{ width:200px; height:200px; } .bg{ background:red; } </style> </head> <body> <div id="div">php 中文網(wǎng)</div> <script type="text/javascript"> $("#div").addClass('bg'); </script> </body> </html>
submitReset Code