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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:07:48+00:00 2026-06-05T23:07:48+00:00

I just started out with jQuery and really only need it for some very

  • 0

I just started out with jQuery and really only need it for some very basic stuff. Here’s what I’m trying to do:

I separate content into an “.overview” div and a “.detail” div. jQuery looks through all the “.detail”-divs, moves up one element (.prev(“.overview”)) and appends a button. Then it scales down all the “.detail” divs to zero, and uses the buttons to reveal/hide them respectively.

I had first hard-coded the buttons, but it seemed tedious and unnecessary. But as soon as I generate them dynamically, the reveal/hide function does not work anymore. I searched around, but I might not be using the right terms…

Here’s my html:

<div class="title">
    <h2>Title</h2>
</div>
<div class="overview">
    <p>...</p>
</div>
<div class="detail">
        <p>...</p>
</div>

And this is the jQuery code (in a separate file):

$(document).ready(function() {

    $(".detail").each(function() {
        $(this).prev("div").append("<div class=\"expand\"><a href=#>more</a></div>");
        $.data(this, "realHeight", $(this).height());
    }).css({ overflow: "hidden", height: "0" });

    $(".expand").toggle(function() {
        $(this).html("<a href=#>less</a>")
        var div = $(this).next(".detail")
        div.animate({ height: div.data("realHeight")+21 }, 250);        
    }, function() {
        $(this).html("<a href=#>more</a>")
        $(this).next(".detail").animate({ height: 0 }, 250);
    });

});

I would hugely appreciate if you could point me in the right direction. Or, if it’s a stupid one, just tell me what I need to do a search for. 🙂

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-06-05T23:07:49+00:00Added an answer on June 5, 2026 at 11:07 pm

    $.next() get the next sibling and “.detail” is not a sibling of “.expand” in your DOM structure. You may want to get to the parent (“.overview”) and then get the next().

    Or change the structure so that they are siblings.

    EDIT:
    In your code you do this, and that’s why they are not siblings:

    $(".detail").each(function() {
        $(this)
            .prev("div") // <- this gets the overview div
            .append("<div class=\"expand\"><a href=#>more</a></div>"); // <- this creates the "expand" as a child of the overview div (so not a sibling of details)
    

    Try this fiddle with “parent” working, using the base code in the question.

    Here is another fiddle with the div “expand” inserted as sibling using insertBefore. It works exactly the same and you don’t need the .parent() call.

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

Sidebar

Related Questions

I just started out with C and have very little knowledge about performance issues
I have just started out with testing some php mvc framework In it, it
I am just getting started with JS Unit Testing and am trying out qUnit.
I just started out on jQuery and want to use it to solve this
I just started working with jQuery and I have been searching for some type
I just started doing jQuery last week, and so far I already made some
I just started looking into jQuery yesterday, before this I programmed in only PHP.
I've just started out learning iOS development. I'm using some NSLog statements in my
Okay, I really need some help with this. I'm new with designing and stuff,
I just started out with a new site and I decided to use DOMImplementation

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.