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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:33:58+00:00 2026-06-06T22:33:58+00:00

I have a table that contains multiple dropdown menus for a list of profile

  • 0

I have a table that contains multiple dropdown menus for a list of profile images. I’ve tagged the list element with the DB id of the photo so I can perform the associated action. I’ve coded my table to look like this:

<table class="table table-bordered">
<tbody>
<tr>
  <td><img src="/photos/files/5/m/131309a4fb918110ed1061e90a715eca.jpeg"/></td><td><div class="btn-group">
  <a class="btn btn-primary" href="#"><i class="icon-user icon-white"></i> User</a>
  <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
  <ul class="dropdown-menu">
    <li id="5"><a href="#"><i class="icon-pencil"></i> Edit</a></li>
    <li id="5"><a href="#"><i class="icon-trash"></i> Delete</a></li>
  </ul>
</div>
</tr>
<tr>
  <td><img src="/photos/files/5/m/b19102d8ba1158e2a139ffa84e8e8540.jpeg"/></td><td><div class="btn-group">
  <a class="btn btn-primary" href="#"><i class="icon-user icon-white"></i> User</a>
  <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
  <ul class="dropdown-menu">
    <li id="7"><a href="#"><i class="icon-pencil"></i> Edit</a></li>
    <li id="7"><a href="#"><i class="icon-trash"></i> Delete</a></li>
  </ul>
</div></tr>    
</tbody>
</table>

My jquery attempt is below but isn’t working:

    $('.dropdown-menu').on('click', 'li', function(e){

         if ($(this).attr('class')=='icon-pencil') {
                var id = $(this).attr('id');
                alert("ID= " + id);
         }

    });

I never hit my alert code so what am I missing here?

Also is there a better way to track the photo ID’s or will they work this way?

  • 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-06T22:33:59+00:00Added an answer on June 6, 2026 at 10:33 pm

    You have li > a > .icon-pencil in your structure but you’re looking for this.className on li click (which is, obviously, the li). Try this:

    $('.dropdown-menu').on('click', 'li', function(){
        if ($(this).find('icon-pencil').length > 0) {
            var id = this.id;
            alert("ID= " + id);
        }
    });
    

    A cleaner approach would be to listen for click on the anchor, since this is the usual click element:

    $('.dropdown-menu').on('click', 'a', function(){
        if ($(this).children('.icon-pencil').length > 0) {
            var id = $(this).closest('li').attr('id');
            alert("ID= " + id);
        }
        return false;
    });
    

    And the cleanest solution would be to set the ID’s only on .dropdown-menu, so they are unique, then get it via .closest(‘ul’) instead of .closest(‘li’).

    PS: having duplicate IDs is always bad.

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

Sidebar

Related Questions

I have a table that contains dates, the table can have multiple dates in
I have a table that contains members names and a field with multiple ID
Here is my situation: I have one table that contains a list of drugs
I have a DB table that contains a comma separated list of ID's (ints)
I have a table that contains multiple rows. Each row contains 5 columns (or
I have a table that contains events, to list these events I loop through
I have a table that contains multiple records for each day of the month,
I have a mysql database table that contains multiple user photos. I am trying
I have a generated table that contains multiple rows with each row containing a
I have a table that contains all the data about users . Users can

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.