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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:42:35+00:00 2026-05-18T05:42:35+00:00

I have a div class=parent . When I click on it I need to

  • 0

I have a div class=”parent” . When I click on it I need to clone div class=”child” and show them depending on the parent area I clicked. The problem arises when I click on the div class=”child”, another child div appears which is the behavior I don’t really want.
One way to overcome this trouble is to write something like this:


$('.parent').click(function(event){
if (event.target.className != 'child'){
$('.child').clone().show();
}
});

I consider that this is not very elegant as, if inside of div class=”child” would be children, then you have to put them in the if() statement also.
Could someone tell me how to manage this problem. Probably there is a way to put all children of the div class=”child” in an array and to loop over them.
Any ideas and thoughts appreciated,
Thanks

  • 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-18T05:42:35+00:00Added an answer on May 18, 2026 at 5:42 am
    $('.parent').click(function(event){ 
      if (event.target === this){
         $('.child').clone().show();
      }
    });
    

    Should only target parent and not the children. From the jQuery docs:

    event.target:
    The target property can be the element
    that registered for the event or a
    descendant of it. It is often useful
    to compare event.target to this in
    order to determine if the event is
    being handled due to event bubbling.
    This property is very useful in event
    delegation, when events bubble.

    Source

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

Sidebar

Related Questions

i have this html code: <div id=ht_key class=ht_all> <div class=ht_bottom> <div class=ht_bottom_p> <span class=ht_bottom_o>
The esample is here: http://jsfiddle.net/SsPqS/ I have a div with class=record I add a
I am dynamically appending form elements. The newly appended elements need to have distinct
I need to get the content of some specific elements using jquery, the problem
I have some buttons that when clicked, invoke jQuery to remove and replace their
I have a list as such : <ul id=yearMenu> <li>Select a year</li> <li><a href=AJAX/2010PR.html>2010</a>
I have adapted a jQuery tabbed interface tutorial to create an interface for viewing
I honestly tried to do search before posting but couldn't find something specific. So
Using an unordered list for my menu .. I've got the selection for 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.