Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 147739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:50:03+00:00 2026-05-11T08:50:03+00:00

Got some code here that isn’t working: $(#sidebar ul li:last).each(function(){ $(this).addClass(last); }); Basically I

  • 0

Got some code here that isn’t working:

$('#sidebar ul li:last').each(function(){       $(this).addClass('last'); }); 

Basically I have 3 lists and want to add a class (last) to each item appearing last in each unordered list.

<ul>       <li>Item 1</li>       <li>Item 2</li>       <li class='last'>Item 3</li> </ul> 

Hope that makes sense, Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:50:04+00:00Added an answer on May 11, 2026 at 8:50 am

    Easy mistake to make. Try this:

    $('#sidebar ul li:last-child').addClass('last'); 

    Basically :last doesn’t quite do what you think it does. It only matches the very last in the document, not the last in each list. That’s what :last-child is for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We minify, merge and gzip our site wide JS (which… May 12, 2026 at 12:27 am
  • Editorial Team
    Editorial Team added an answer I think you mean this post. And I have to… May 12, 2026 at 12:27 am
  • Editorial Team
    Editorial Team added an answer I think you want the 'afterNodeChange' event. Study the API… May 12, 2026 at 12:27 am

Related Questions

Got some code here that isn't working: $(#sidebar ul li:last).each(function(){ $(this).addClass(last); }); Basically I
I feel like there is an obvious answer to this, but it's been eluding
Here's a mockup: A mockup http://img.skitch.com/20090228-mqdj17xijycc98spf181a8q6q7.jpg I have been trying to find some sample
I've got some library code that works on a range of .NET runtimes (regular,
I'm trying to go through the NerdDinner example chapter from the ASP.Net MVC 1.0

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.