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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:07:14+00:00 2026-06-13T20:07:14+00:00

I have code similar to this: <div id=content> <div id=child1></div> <div id=child2></div> </div> I

  • 0

I have code similar to this:

<div id="content">
    <div id="child1"></div>
    <div id="child2"></div>
</div>

I am using jQuery click events

$('#child1').click(function(){
var page = "value1";

    $('#content').hide();
    $('#content').load('includes/'+ page +'.php', function () {
        $('#content').fadeIn(speed);
    });
    return false;
});

However, when clicking on any of the content in the loaded #content ID the div children return the parent ID. How can I select the child ID while ignoring the parent?

The actual HTML is more complicated so the value of the child on the page wouldn’t simply be #content#child1, is there a way to have the JS ignore #content and see #child1?

If I use code like

$('div').click(function(){
    alert($(this).attr("id"));
    return false;
});

the value returned when clicking “#child1” or is “#content”.

  • 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-13T20:07:15+00:00Added an answer on June 13, 2026 at 8:07 pm

    I may be reading this wrong, but you’ve completely overwritten the the contents of #content. The #child1 and #child2 divs no longer exist once the load command has completed.

    Even if your loaded data includes a #child1 div, it is not the same DOM node that you originally attached the click event to. That old node is gone, replaced by your loaded data, and the event handlers are gone too.

    If you want to keep listening to #child1.click() events after the old child nodes are deleted, you have two options:

    • Re-bind events after the load completes
    • Use event delegation on the #content node

    Event delegation allows you to bind a listener on #content that will fire when events bubble up from the child elements:

    $('#content').on('click', '#child1', function(evt) {
        // event handler here
        // this points to the element clicked ('#child1')
    });
    

    This will effectively keep your #child1 click handler alive even after you have replaced the nodes with totally new HTML.

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

Sidebar

Related Questions

I have a similar code snippet like this class Search { public function search($for,
I have code similar to the following: <div class=container> <div class=overlay> // hover content
I have a content editable div. Within this I am inserting a <pre>some code</pre>
Let's say I have this code: <div id=content> </div> and I use a simple
I have code similar to this: public List<string> Expected = new List<string>(); public int
I have code that is similar to this: public xyz (int? a) { if
I have code similar to the following with a URL like this... If I
I have a piece of code VERY similar to this one http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching I the
I have a piece of code that look similar to this: <xsl:choose> <xsl:when test=some_test>
I have an XML layout similar to this (the XML and code is a

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.