JS for interlaced color

Source: Internet
Author: User

<!        DOCTYPE html>Body,ul{margin:0;padding:0;}                ul{width:500px;                margin:100px Auto;                padding:10px;                Border:solid 1px #E3E3E3; List-Style:none; Line-height:2;                } li{padding:8px 10px; Border-radius:8px; }                    /*Li:nth-child (odd) {background: #E7E7E7;            } li:nth-child (even) {background: #EEE8AA;                } li:hover{background:red;            Color:white; }*/. bg1{background: #E3E3E3;            }. bg2{background: #EEE8AA;                }. bg3{Color:white;            background:red; }        </style> //by the class name is an array of classes, the data type is object, it also has its own corresponding index value, index starting from 0        varNews = Document.getelementsbyclassname (' news ') [0]; //created a property for the news element, Matt, and assigned a value Mvalue        //1.setAttribute (property name, property value) Set Property GetAttribute ("property name")//News.setattribute ("MAtt", "Mvalue");//Console.log (News.getattribute ("MAtt"));        //2. HTML custom attribute Tag element. property = "attribute value";//News.att = "value";//Console.log (News.att)        //Get the tag element by tag name, get the class array        varLis = news.getelementsbytagname (' li '); Console.log (typeoflis); //traversing Lis         for(vari = 0; i < lis.length; i++) {            if(i% 2 = = 1) {Lis[i].classname= "BG1"; //Customizing a property to temporarily store the value of the current classname//lis[i].oldclassname = "BG1";}Else{lis[i].classname= "Bg2";//lis[i].oldclassname = "Bg2";            }                        //Mouse Events            //onmouseoverLis[i].onmouseover =function(){                //when the mouse is over, change the classname, the original classname temporarily stored up                 This. Oldclassname = This. ClassName; //lis[i].classname = "Bg3";//Loop internal Set event function, event function after the loop execution is completed;                 This. ClassName = "Bg3"; }                        //Mouse Leave event onmouseoutLis[i].onmouseout =function(){                //How do you get back to the original style?                //How do I add a custom attribute to HTML?                 This. ClassName = This. Oldclassname; }        }                        </script>

JS for interlaced color

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.