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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:35:29+00:00 2026-05-28T15:35:29+00:00

I have hidden Divs with .display-link classes that are two levels up from an

  • 0

I have hidden Divs with “.display-link” classes that are two levels up from an input box. When an input (checkbox) is clicked, it should display the hidden link in the parent’s previous sibling’s wrapper.

Or another way to say it is, when an input checkbox is clicked it should find the previous div with the class .display-link and show() that.

I am having trouble traversing the elements to reach this div with this class. It should only display the one, previous div.

<!DOCTYPE HTML>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>

$(document).ready(function(){

$(".display-link").hide();//hide all links

$('input').click (function ()
    {
    $(this).closest(".display-link").show();//doesn't work
    $(this).closest("div.display-link").show();//doesn't work
    myInput = $(this);
    $(myInput).closest(".display-link").show();//doesn't work
    $(myInput).parents(".display-link").show();//doesn't work
    $(myInput).prevUntil(".display-link").show();//doesn't work
    });
});
</script>
</head>

<body>
<div class="accordion-button">First Heading
  <div class="display-link">LINK</div>
</div>
<div class="collapsible">
  <div class="input-row">
    <input id="checkbox01" name="checkbox01" type="checkbox" value="value01"  />
    <label for="checkbox01" >Name 1</label>
  </div>
  <div class="input-row">
    <input id="checkbox02" name="checkbox02" type="checkbox" value="value02"  />
    <label for="checkbox02" >Name 2</label>
  </div>
</div>
<div class="accordion-button">Second Heading
  <div class="display-link">LINK</div>
</div>
<div class="collapsible">
  <div class="input-row">
    <input id="checkbox03" name="checkbox03" type="checkbox" value="value03"  />
    <label for="checkbox03" >Name 3</label>
  </div>
</div>
</body>
</html>

I need to go out of the collapsible div and into the accordion-button div down to the display-link 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-05-28T15:35:30+00:00Added an answer on May 28, 2026 at 3:35 pm
    $('input').on('click', function () {
        $(this).parents('.collapsible').prev('.accordion-button').children('.display-link').show();
    });
    

    Here is a demo: http://jsfiddle.net/hazvX/

    This finds the parent .collapsible element, finds the previous .accordion-button element, then selects it’s child .display-link element.

    Your HTML shows that there are two .display-link elements and three inputs. If you want the inputs to find the first possible (previous) .display-link elements you can use .prevAll() in place of .prev():

    $('input').on('click', function () {
        $(this).parents('.collapsible').prevAll('.accordion-button').eq(0).children('.display-link').show();
    });
    

    Here is a demo: http://jsfiddle.net/hazvX/1/

    Notice I also added .eq(0) after the .prevAll() function to only get the first returned element (since there can be multiple).

    Note that .on() is new in jQuery 1.7 and in this case is the same thing as .bind().

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

Sidebar

Related Questions

I have two divs that are hidden from view until corresponding image links are
I have a series of divs that I've hidden with css display:none;. <div id=
I have a number of dropdowns and divs that are hidden when the page
I have a menu and three hidden divs that show up depending on what
I have items contained in an unordered list. I have hidden divs (using display:none;)
I have a page I am working with that has several hidden DIVs that
So I have a bunch of divs that are hidden on load unless a
I have an array of links that when clicked will bring up a hidden
I have two buttons and two hidden divs containing different information. I'm trying to
I have some forms, which are in some DIVs. DIVs are hidden, and are

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.