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

  • Home
  • SEARCH
  • 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 678727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:10:54+00:00 2026-05-14T01:10:54+00:00

I’m having some trouble figuring this out. I have an unordered list menu that

  • 0

I’m having some trouble figuring this out. I have an unordered list menu that I want to style all the last elements with a folder icon and style all the expandable (parent) elements with a plus.gif image. I wanted to simply change the class by using .addclass() using jquery, which will contain the css to add the background-image. My jquery code below is only selecting the “:last-child”, which is placing a folder icon on the last element in the list. i need to place a folder icon in front of all the “li’s” that don’t hav any children, and place a plus icon in front of all those that do have children. Is there a way to accomplish this?

Here’s my HTML:

<ul id="nav">
 <li>Heading 1
  <ul>
   <li>Sub page A
    <ul>
     <li>Sub page A - 1
      <ul>
       <li>A - 1: 0</li>
       <li>A - 1: 1</li>
       <li>A - 1: 2</li>
      </ul>
     </li>
     <li>Sub page A - 3</li>
     <li>Sub page A - 2</li>
    </ul>
   </li>
   <li>Sub page B</li>
   <li>Sub page C
    <ul>
     <li>Sub page C - 1
      <ul>
       <li>C - 1: 0</li>
       <li>C - 1: 1</li>
       <li>C - 1: 2</li>
      </ul>
     </li>
     <li>Sub page C - 3</li>
     <li>Sub page C - 2</li>
    </ul>
   </li>
  </ul>
 </li>
 <li>Heading 2
  <ul>
   <li>Sub page D</li>
   <li>Sub page E</li>
   <li>Sub page F</li>
  </ul>
 </li>
 <li>Heading 3
  <ul>
   <li>Sub page G</li>
   <li>Sub page H</li>
   <li>Sub page I</li>
  </ul>
 </li>
</ul>

Here’s the jquery code:

    $(function(){

 //add class to last item in each list
 $('#nav li').find('li:last').addClass('menu_last_child');
});
  • 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. Editorial Team
    Editorial Team
    2026-05-14T01:10:54+00:00Added an answer on May 14, 2026 at 1:10 am

    This will add your class to all li‘s that do not have children

    $("#nav li:not(:has(li))").addClass('menu_last_child');
    

    This will add a class to all li‘s that DO have children

    $("#nav li:has(li)").addClass("menu_parent");
    

    Also keep in mind that there is a difference between :last and :last-child. The former will select only the last item in the returned set of items matching the selector, while the latter will return all items that are the last in the context of their parent (same as css :last-child selector)

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

Sidebar

Related Questions

No related questions found

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.