Introduction
Today I came to work on a requirement of selecting the entire li from a ul but not the last one. So, I thought to share that info with you. Hope you will like it.
Using the code
You can see the jsfiddle here: JSFIDDLE.
Here I have ul list items as follows;
- <ul>
- <li>Sibeesh</li>
- <li>Sibi</li>
- <li>SibeesPassion</li>
- <li>Buddy</li>
- <li>NA</li>
- </ul>
- <ul>
- <li>Sibeesh</li>
- <li>Sibi</li>
- <li>SibeesPassion</li>
- <li>Buddy</li>
- <li>NA</li>
- </ul>
- <ul>
- <li>Sibeesh</li>
- <li>Sibi</li>
- <li>SibeesPassion</li>
- <li>Buddy</li>
- <li>NA</li>
- </ul>
In that list I have mentioned my nick names , please be noted that I have mentioned the last li as NA, which means I don’t want the JQuery selector to select that particular li item.
Here I am appending “--My Nick Name” to the li items, except to the last one.
- $('ul li:not(:last-child)').append(" --My Nick Name ");
So here is my output
Output - Sibeesh --My Nick Name
- Sibi --My Nick Name
- SibeesPassion --My Nick Name
- Buddy --My Nick Name
- NA
- Sibeesh --My Nick Name
- Sibi --My Nick Name
- SibeesPassion --My Nick Name
- Buddy --My Nick Name
- NA
- Sibeesh --My Nick Name
- Sibi --My Nick Name
- SibeesPassion --My Nick Name
- Buddy --My Nick Name
- NA
- Points of Interest
- JQuery
- Historyy
- 1st Version: 12-12-2014