CSS line-by-line color change

Source: Internet
Author: User
I tested it through a simple example and found that I still like to use JQ. Although very simple, I wrote down the learning process, haha... HTML file: <HTML>
<Title> line-by-line color change </title>
<Li> 111111 </LI>
<Li> 222222 </LI>
<Li> 333333 </LI>
<Li> 444444 </LI>
</Html> Method 1 , Implemented through jquery (do not forget to import jquery. JS): <SCRIPT>
$ (Document). Ready (function (){
$ ("Li: odd" ).css ("background", "#9fb7f6 ");
$ ("Li: Even" ).css ("background", "# b6c8f8 ");
</SCRIPT> Method 2 <Style type = "text/CSS">
Ul. myul1 Li {background-color: expression (this. sourceindex % 2 = 0? '#9fb7f6': '# b6c8f8 ');
</Style> Method 3 , Implemented through CSS and JS (Note: JS should be followed by UL as much as possible, rather than . Li01 {Background: #9fb7f6 ;}
. Li02 {Background: # b6c8f8 ;}
</Style> <script language = "JavaScript">
Objname = Document. getelementsbytagname ("Li") for (I = 0; I <objname. length; I ++ ){
(I % 2 = 0 )? (Objname (I). classname = "li01") :( objname (I). classname = "li02 ");}
Related Article

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.