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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:30:58+00:00 2026-06-12T12:30:58+00:00

let say I have a parent element which has so many nested child elements

  • 0

let say I have a parent element which has so many nested child elements inside of itself:

<div id="p">
    <div id="c1">
        <div id="c2"></div>
        <div id="c3"></div>
    </div id="c4">
        <div id="c5"></div>
    </div>
</div>

I’ve already bind a click event on the parent:

$('#p').bind('click', function() {
    alert($(this).attr('id'));
});

Because the event is assigned to the parent element, I always see the parent id, however, I’m wondering if there is any possible way to find out which of this child elements has been clicked?

I also can’t assign any event to the child elements or remove the event listener from parent div.

  • 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-12T12:31:00+00:00Added an answer on June 12, 2026 at 12:31 pm

    You need to pass event object to function to get the item that triggered the event, event.target will give you the source element.

    Live Demo

     $('#p').bind('click', function(event) {
        alert(event.target.id);
     });
    

    or

    Live Demo

    $('#p').bind('click', function(event) {
        alert($(event.target).attr('id'));
    });
    

    Edit

    The first method event.target.id is preferred over second $(event.target).attr('id') for performance, simplicity and readability.

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

Sidebar

Related Questions

Let's say I have this markup: <div class=foobar> <div style=height:expression(this.parent.style.height + 'px')></div> </div> My
Let say I have 1 parent data and 3 child data like a chain:
Let's say I have <parent> <module-prj-1> <module-prj-2> <module-prj-3> Hypothetically, module-prj-1 is a project which
Let's say I have a parent class and child class as below Parent Class:
Let's say I have a simple parent->child class structure as shown below Public Class
Let's say I have two classes, Parent and Child. These two are related via
Let's say I have a parent/child-relationship ob objects and try to create a parent
let's say I have to tables: Customer (parent) & Address (child). They are associated,
Let's say I have three div elements with classes a , b , and
Let's say I have a parent div with a fixed width of 320px and

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.