jQuery class attribute value manipulation
The previous chapter introduced the content:
This section adds the following content:
$().addClass(value); //Add an information value to the class attribute$().removeClass(value); //Delete an information value in the class attribute$().toggleClass(value); //Toggle effect, delete it if it exists, add it if it doesn’t
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ $("div").addClass('s2'); } function f2(){ $("div").removeClass('s2'); } function f3(){ $("div").toggleClass('s2') } </script> <style type="text/css"> .s2{ width:250px; height:25px; background: yellow; } </style> </head> <body> <div class="s1">歡迎大家學(xué)習(xí)我們的jQuery課程</div> <input type="button" value="設(shè)置" onclick="f1()" /> <input type="button" value="刪除class的屬性值" onclick="f2()" /> <input type="button" value="開關(guān)class屬性值的操作" onclick="f3()" /> </body> </html>