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 6585155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:37:35+00:00 2026-05-25T16:37:35+00:00

I have a number of list items called selectedli having with the css background-color:

  • 0

I have a number of list items called selectedli having with the css background-color: #efefef;

I want to get the value of the last highlighted list item that has the selectedli class applied to it.

This is my code…

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    $('#btnSelect').click(function() {
        alert( $('#wrapper').find('li').filter("[class=leaf]").last().text() ); //bingo
        alert( $('#wrapper').find('li').hasClass('selectedli').last().text() ); //fail to get value when the class got 2 value inside...
        alert( $('#wrapper').find('li').filter('selectedli').last().text() ); //fail to get value when the class got 2 value inside...
        alert($('#wrapper').find('li .selectedli').last().text());
    });
</script>

<div id="wrapper">
    <div id="panel" class="cats1">
        <ul id="list_items">
            <li class="root" data-category_id="1">Fashion</li>
            <li class="root selectedli" data-category_id="2">Computer</li>
        </ul>
    </div>
    <div id="panel" class="cats1">
        <ul id="list_items">
            <li class="root" data-category_id="5">Laptop</li>
            <li class="root selectedli" data-category_id="6">Monitor</li>
        </ul>
    </div>
    <div id="panel" class="cats1">
        <ul id="list_items">
            <li class="leaf" data-category_id="13">LCD Dell</li>
            <li class="leaf selectedli" data-category_id="14">LCD Acer</li>
        </ul>
    </div>
</div>

<input type="button" id="btnSelect" value="Select">

I can’t seem to get my code to work. Could someone please assist me to fix the problem.

  • 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-25T16:37:36+00:00Added an answer on May 25, 2026 at 4:37 pm

    Try this:

    $("#list_items .selectedli").last().data("category_id");
    

    DEMO (updated): http://jsfiddle.net/ugdYm/1/

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

Sidebar

Related Questions

I have a CheckBox list and I want to get the number of items
I have a list like: list = [[1,2,3],[4,5,6],[7,8,9]] I want to append a number
I have one function which is called on list item Click and list items
I am given an input, N, i have to find the number of list
I have these three lists with the same number of elements List<String>competitoinsIDs = new
i have a list 1 column and 100 rows each with a number the
I have a list of calling codes for all countries(the phone number prefixes), I
I have a checkbox list generated using php depending upon number of coloumns in
I have Python nested list that I'm trying to organize and eventually count number
I have a list of numbers, for example: list=[10,50,90,60] I want to sorte the

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.