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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:47:02+00:00 2026-06-17T23:47:02+00:00

I have a problem with nested li’s and grabbing the ID of the element

  • 0

I have a problem with nested li’s and grabbing the ID of the element clicked.

Assume this is my code:

<ul>
    <li id="folderLink_1">Link 1</li>
    <li id="folderLink_2">Link 2
        <ul>
            <li id="folderLink_3">Link 2.1</li>
            <li id="folderLink_4">Link 2.2</li>
        </ul>
    </li>
<ul>

I also have this jQuery:

$('[id^=folderLink_]').live('click',function(){
    alert($(this).attr('id'));
});

When I click on Link 1, I just get the one ID alerted to me, folderLink_1.
However when I click on link 2.1, not only do I get folderLink_3, but also folderLink_2 one after another.

I’ve looked around, and tried using the event.stopPropagation(), however this stops subsequent actions from taking place too which are needed.

The idea is, the folders act as an image library folder structure. When you click a folder, it saves the ID of that folder to a JS variable. When a folder with images contained within it is clicked, ajax retrieves a URL, using the ID in the querystring.

I have tried wrapping the text within the LI around a span, however that I have images around the text which need to act in the same way (if clicked save the ID).

I have attached images for better help.

Step One: Click the menu item anywhere in the red section
Step Two: When the link is clicked, the ID of that folder is saved, and another menu slides right
Step Three: The new menu slides into where the old one was, and the folder name appears in the carbon fiber section at the top

Image One (Top Left): Click the menu item anywhere in the red section

Image Two (Top Right): When the link is clicked, the ID of that folder is saved, and another menu slides right

Image Three (Bottom Left): The new menu slides into where the old one was, and the folder name appears in the carbon fiber section at the top

When the new link (in image three) is clicked, not only does it load content in an area outside of the picture provided, but also records the ID of that LI clicked.

If anyone has any suggestions for getting this to only save the ID of the li clicked, it’d be greatly appreciated.

  • 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-06-17T23:47:03+00:00Added an answer on June 17, 2026 at 11:47 pm

    You should be using on(), as live() is deprecated, and e.target.id will give you the ID of the element that was actually clicked :

    $(document).on('click', '[id^=folderLink_]', function(e){
        if (this===e.target) alert(e.target.id);
    });
    

    FIDDLE

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

Sidebar

Related Questions

I have this problem: After instantiating this Window, open all nested expanders on the
I have a problem with this piece of code: var elements; var current =
I have a problem when invoking nested std::bind expressions. The following code demonstrates the
I have a problem with ie 7 and nested lists - this looks freaky
I have a problem with nested templates and their template specialization. Given the following
I'm having a problem with nested bindings with Knockout.JS For example if I have
Is it possible to tie nested generics/captures together? I often have the problem of
I have a table with a tags nested inside the td tags. Problem is,
I'm having a problem with some for nested loops that I have to convert
I have problem with my query on C, I’m using the oci8 driver. This

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.