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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:38:35+00:00 2026-05-20T22:38:35+00:00

I am having trouble removing the last DD and DT tags from a definition

  • 0

I am having trouble removing the last DD and DT tags from a definition list when prepending new content using .each. My goal is to remove a set of DD and DT tags with each iteration (as new DD and DT tags are prepended). The following is example code I am using:

shouts_list = $("#shouts dl#shouts_list");
$.each(json.shouts, function (id, shout) {
            $("<dt>" + shout.name + "</dt><dd>" + shout.message +  "</dd>").hide().prependTo(shouts_list).slideDown('slow', 'swing', function() {
            $("#shouts_list > dt:last, #shouts_list > dd:last").slideUp('slow', 'swing');
            }).fadeIn();
        });

Each time my json object contains multiple items, only one set of DT and DD are removed from the end.

I am learning jQuery and JavaScript slowly and have been stuck on this issue for a while. What would be a good way to remove items from the end of the list for each iteration?

  • 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-20T22:38:36+00:00Added an answer on May 20, 2026 at 10:38 pm

    Only one element is being removed from the list because the each loop is going through all the items in json.shouts before the first slideUp call finishes (ie the loop is too fast or slideUp is too slow). This means that each time this executes:

    $("#shouts_list > dt:last, #shouts_list > dd:last").slideUp('slow', 'swing');
    

    the original last item in the list is always being found, so you’re actually calling slideUp on the same element json.shouts.length number of times. You need to get all the original items in the list before the each loop starts and count backwards to remove one for each new item added.

    This should do the trick:

    shouts_list = $("#shouts dl#shouts_list");
    var existingDts = shouts_list.find("> dt");
    var existingDds = shouts_list.find("> dd");
    
    $.each(json.shouts, function (id, shout) {
         $("<dt>" + shout.name + "</dt><dd>" + shout.message +  "</dd>")
           .hide().prependTo(shouts_list)
           .slideDown('slow', 'swing', function() {
               $(existingDts[existingDts.length - 1 - id]).slideUp('slow', 'swing');
               $(existingDds[existingDds.length - 1 - id]).slideUp('slow', 'swing');
         })
        .fadeIn();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to be having some trouble removing some events from an element using
I am using Ruby and I am having trouble removing a gem. The gem
I'm new to DOM and I'm having trouble removing multiple images that I loaded
I am having trouble programmatically removing stacks from a view. I am doing things
I am having trouble with hiding/removing the card owner and image from the card
I'm having some trouble dynamically removing UITextFields from my scrollview when the user taps
I'm having trouble removing a gem from my system. When i ask gem where
I am having trouble removing objects from nsmutable array. Here it is. NSURL *url
Im having some trouble removing part of a cloned element: console.log($(this).closest('tr').clone().find('td:last')); //this is the
I am having trouble removing files from my main bundle. When I delete them

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.