Operation of jquery related class attributes

Source: Internet
Author: User

1<! DOCTYPE html>2"en">34<meta charset="UTF-8">5<title>wrap</title>6<script type="Text/javascript"Src=".. /jquery/jquery-1.11.3.min.js"></script>7<style type="Text/css">8. lianjie{display:inline-block;border:1px Solid Red}9 . border{border:1px Solid Red}Ten . border1{outline:4px dotted Green} One</style> A -<body> -<a href="http://www.baidu.com" class="Baidu"> Baidu </a> the<a href="http://www.souhu.com" class="Souhu"> Baidu </a> -<a href="http://www.xinlang.com" class="XINLNG"> Baidu </a> -"1.jpg"alt="This is a picture ."/> -  +<script type="Text/javascript"> - $ (document). Ready (function () { +$("img"). AddClass (" Picture");//Add Class attribute A$("img"). Removeclass (" Picture"). AddClass ("T_pic");//Delete and add Class attribute atConsole.log ($ ("img"). Hasclass ("T_pic"));//Hasclass Detect if a class attribute exists -  -$("a:odd"). AddClass ("Lianjie");//odd odd even even -  -$("a"). addclass (function (index,eclass) {//dynamically adding the Class Property index is an index Elcass processing the class property owned by the current element -             if(index%2==0){ in                 return "even"; -}Else{ to                 return "Odd"; +             } -         }); the  *$("a"). Filter (": Odd"). AddClass ("Oddclass"). End ()//filter () filters the matching list of elements to the previous state until the last destructive operation is returned by the result set end () of the expression match $. Filter (": Even"). AddClass ("Evenclass");Panax Notoginseng  -$("<button>toggle</button>"). AppendTo ("Body"). Click (dotoggle); the  + function Dotoggle (e) { A //$ ("img"). Toggleclass ("border");//Toggleclass Switch Class the //$ ("img"). Toggleclass ("Border Border1");//Toggleclass Switching multiple class + //$ ("img"). Toggleclass ();//toggleclass () switch all class without adding parameters - //$ ("img"). Toggleclass ("border", false);//Toggleclass () the second parameter is false to delete only $ //$ ("img"). Toggleclass ("Border", true);//Toggleclass () The second parameter is a true value added $$("a"). Toggle (function (index,currentclass) { -  -                 if(index%2==0){ the                     return "Border"; -}Else{Wuyi                     return "Border1"; the                 } -  Wu             }); -  About E.preventdefault (); $         } -  -     }); -  A</script> +</body> the

Operation of jquery related class attributes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.