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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:33:30+00:00 2026-06-11T15:33:30+00:00

Disclaimer: I am fully aware that the id attribute is for unique IDs. In

  • 0

Disclaimer: I am fully aware that the id attribute is for unique IDs. In my case, when the ajax request takes longer than usual it can glitch, causing two same chat messages. I am also aware that there are similar questions out there like this, but I have been unable to find one that solves my issue.


This is what I want to do:

  1. Are there any duplicate IDs inside the div chat_log?
  2. What are they?
  3. Delete all the duplicates
    • Making sure that the original one is still there.

I’ve tried using the following code:

         $('[id]').each(function () {
            var ids = $('[id=' + this.id + ']');
            if (ids.length > 1 && ids[0] == this) {
                $(ids[1]).remove();
            }
        });

But I’m not sure how I can adapt that method to my situation, nor am I sure if it would be possible.

  • 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-11T15:33:31+00:00Added an answer on June 11, 2026 at 3:33 pm

    How can you ensure that something is unique? Let’s say you have a bunch of vegetables (cucumbers, turnips, pizzas etc.) You want to ensure colour uniqueness, making sure that any colour only appears once. How’d you do it?

    What I’d do is make a list. I’d go through every vegetable, and inspect its colour. If the colour is already on the list, we’ll remove that vegetable from the bunch. Otherwise, we leave it as-is and add its colour to our list.

    Once that logic is understood, all we need is to convert it to code! What a fantastically trivial thing to do (on paper, of course.)

    //assumes $elem is the element you're deleting duplicates in
    
    //create the ids list we'll check against
    var ids = {};
    
    //go over each element
    var children = $elem.children();
    for ( var i = 0, len = children.length; i < len; i++ ) {
        var id = children[ i ].id;
    
        //was this id previously seen?
        if ( ids.hasOwnProperty(id) ) {
            $( children[i] ).remove();
        }
        //a brand new id was discovered!
        else {
            ids[ id ] = true;
        }
    }
    //done!
    

    This is the very simple, plain logic version. You can make much fancier ways with some weird sizzle selectors, but this should get you started.

    Demo (without jquery): http://tinkerbin.com/qGJpPsAQ

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

Sidebar

Related Questions

Disclaimer: I'm fully aware that the best way to represent date/times is either Unix
Disclaimer Yes, I am fully aware that what I am asking about is totally
Disclaimer: I'm a rails n00b. I'm playing around with a simple helper function that
Disclaimer: this question is driven by my personal curiosity more than an actual need
Disclaimer : I'm quite a novice to RoR, but not with Ruby (if that
Disclaimer: I've looked through all the questions I can find and none of them
Disclaimer: this is needed for an old and ugly codebase that I'd much rather
Disclaimer : this is a strange issue that only happens in a Kindle Fire
Disclaimer: the following is a sin against XML. That's why I'm trying to change
Disclaimer, Please pardon grammatical syntax. I'm using the simple linkedin php library that is

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.