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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:56:17+00:00 2026-06-07T19:56:17+00:00

Alright. I have created a custom object that I am using to build a

  • 0

Alright.
I have created a custom object that I am using to build a list of things. One of the functions for this custom object involves adding the object to a list. In this list, there is a value I assign to each different element that keeps track of how many of that item have been added to the list. Such as:

(3) Object#1
(2) Object#2

3 and 2 of course being the ‘count’ value of that object. My problem is that I am creating the list dynamically by calling:

function Thing(count, value)
{
    this.count=count;
    this.value=value;
}

Thing.prototype.addToList = function()
{
if (this.count == 0)
{
    this.count++;

    var list = document.getElementById("blah");
    var li = document.createElement("li");
    var interior = "<span id='counter'>("+this.count+")</span>";
    li.innerHTML = interior;
    list.appendChild(li);
}
else
{
    this.count++;
    var countInc = document.getElementById("counter");
    countInc.innerHTML = "("+this.count+")";
}
}

This works fine, but if I am to add multiple Objects with separate count values, there is no way to distinguish between them, and as a result, the first ‘counter’ span in the list is altered with the the count value of the most recently added object. All other count values remain the same (1). I have tried:

var interior = "<span id='counter"+this.value+"'>("+this.count+")</span>";

To try and create a unique id each time, but this isn’t working. Basically, I am wondering how I can create new ID values each time I instantiate a new Object.

  • 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-07T19:56:19+00:00Added an answer on June 7, 2026 at 7:56 pm

    try this

    var list = document.getElementById("blah");
    var li = document.createElement("li");
    var interior = "<span id='counter-"+this.count+"'>("+this.count+")</span>";
    li.innerHTML = interior;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright so far I have created a list containing a long list of words
Alright so far I have created a list containing a long list of words
Alright. This is the situation. I have created a website with a black banner
Alright so I have no idea how to even begin doing this But basically
Alright so I have a task, that I have to let the client try
Alright, so I have this collision detection code, and I'm trying to push the
Alright, I have this program to sparse code in Newick Format, which extracts both
I'm having a little predicament switching between views, here. Alright, so, I have this
Alright, I'll try to explain this the best I can. I have an iPhone
Alright, so heres my problem: I have an application I am working with that

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.