Jquery continuous list implementation code

Source: Internet
Author: User

This tutorial will show you how to use jquery to add continuous CSS classes to generate a vivid list. The second example shows how to use jquery's prepend feature to add a Message count to the message list.
Let's take a look at the example.
1A. Add jqueryCode
Download jquery and add the following jquery code between the

Copy code The Code is as follows: <SCRIPT type = "text/JavaScript" src = "jquery. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
$ (Document). Ready (function (){
$ ("# Step li"). Each (function (I ){
I = I + 1;
$ (This). addclass ("item" I );
});
});
</SCRIPT>

Jquery outputs the following HTML source code:

1b. CSS Encoding
Apply the <li> element of the background image. (Step1.png, step2.png, step3.png, etc ).Copy codeThe Code is as follows: # Step. Item1 {
Background: url(step1.png) No-Repeat;
}
# Step. item2 {
Background: url(step2.png) No-Repeat;
}
# Step. item3 {
Background: url(step3.png) No-Repeat;
}


2a. Add continuous content
You can also use this technique to add ordered content and jquery's prepend method. This method is used to generate a count message list.

Copy code The Code is as follows: <SCRIPT type = "text/JavaScript" src = "jquery. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
$ (Document). Ready (function (){

$ ("# Commentlist li"). Each (function (I ){
I = I + 1;
$ (This). prepend ('<SPAN class = "commentnumber"> #' I '</span> ');
});

});
</SCRIPT>

A <span calss = "commentnumber"> count </span> is added for each <li>.

2b. CSS
Style <li>: Position: Relative: place. commentnumber in the upper right corner of the message bar with position: absolute.Copy codeThe Code is as follows: # commentlist Li {
Position: relative;
}
# Commentlist. commentnumber {
Position: absolute;
Right: 0;
Top: 8px;
}

2b. CSS
Style <li>: Position: Relative: place. commentnumber in the upper right corner of the message bar with position: absolute.Copy codeThe Code is as follows: # commentlist Li {
Position: relative;
}
# Commentlist. commentnumber {
Position: absolute;
Right: 0;
Top: 8px;
}

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.