JQuery Not Last Demo

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;
[html]
<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>
[/html]

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.
[js]
$(‘ul li:not(:last-child)’).append(" –My Nick Name ");
[/js]

So here is my output

Output
[html]
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
[/html]

Points of Interest
JQuery

History
1st Version: 12-12-2014

Leave a Reply

Your email address will not be published. Required fields are marked *

Serverless 360