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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:17:23+00:00 2026-05-13T17:17:23+00:00

What is the best way to do this dynamic events linking between divs in

  • 0

What is the best way to do this dynamic events linking between divs in jquery.

my HTML page:

<html>
<body>
<div id="parent1"></div>
<div id="parent2"></div>
<div id="parent3"></div>
<div id="child1"></div>
<div id="child2"></div>
<div id="child3"></div>
</body>
</html>

for each clicked parent i want to .toggle its child

Example :: if parent2 clicked, .toggle will be applied on child2 only

my parents and childs divs are dynamically created so their number is not static, i think .live should be used here, but i have no idea how to achieve that.

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-13T17:17:23+00:00Added an answer on May 13, 2026 at 5:17 pm

    This should do it, using the rel attribute to note link. You could also do the same thing by parsing the ID and so on, but I find this solution more semantic (if it means something) :

    <html>
    <body>
    <div id="parent1" class="parents" rel="child1"></div>
    <div id="parent2" class="parents" rel="child2"></div>
    <div id="parent3" class="parents" rel="child3"></div>
    <div id="child1"></div>
    <div id="child2"></div>
    <div id="child3"></div>
    </body>
    </html>
    
    jQuery(function(){
      jQuery(".parents").live("click", function(){
         jQuery("#"+jQuery(this).attr("rel")).toggle();
      });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way of doing this? tmpnam() returns a path to a
What's the best way to format this for readability? if (strpos($file, '.jpg',1) && file_exists($thumbsdir/$file)
What would be the best way to do this. The input string is <133_3><135_3><116_2>The
what's the best way to do this? I'm no command line warrior, but I
I am trying to figure out the best way to parse this comma delimited
As far as I can tell, the best way to do this is do
After reading this answer: best way to pick a random subset from a collection?
Is this the best way to handle file moving in a windows service? we
What is the best way to free resources (in this case unlock the ReadWriteLock)
This question will expand on: Best way to open a socket in Python When

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.