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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:13:17+00:00 2026-06-12T09:13:17+00:00

I’m working on this form (test) creator where a div containing form elements is

  • 0

I’m working on this form (test) creator where a div containing form elements is cloned using jQuery to create more questions. The original div is hidden. each div also has a button within it that has onClick="javascript:$(this).parent().empty().remove();" attached. My problem is the divs are numbered question1, question 2 etc by checking how many divs with the class question exists and then appending that number to ‘question’ and setting question1(or question2, question3 etc) as the id for the cloned div- Since the original div is hidden there is no need to +1 to the number of divs with that class. But when one if the divs is deleted the numbering gets messed up. Example:
1. Div is added.
2. Div is called Question 1(id=question1)
3. Another div is added.
4. Div is called Question 2(id=question2)
5.First Div is removed.
6.Another div is added.
7.New div is called Question 2(id=question2)
8.Question 2(id=question2) already exists since the second div was not deleted.
I need to renumber the divs when one of them is deleted.
Here’s the code for cloning the divs:

function copyAppendQ() {
  question = document.getElementById("question");
  clone=question.cloneNode(true);
  numberOfQuestions = $('.question').length;
  id = "questioncon"+(numberOfQuestions);
  clone.id=id;
  question.parentNode.appendChild(clone);
  inid= "question"+(numberOfQuestions);
  optionid= "optionsdiv"+(numberOfQuestions);
  $('#'+id+' '+'.'+'questionin').attr('id', inid);
  $('#'+id+' '+'.'+'options').attr('id', optionid);
 $('#' + id + ' h2').html( 'Question ' + numberOfQuestions );
}

and the div (this div is hidden but is cloned with a different id, removing the display:none property set on the original div, when the above function is called)

<div id="question" class="question">
                <h2></h2>
                <input id="questionin" class="questionin" style="width:341px;" ><input type="button" id="remq" onClick="javascript:$(this).parent().empty().remove();" style="background-color:#E12E1E;border:0;width:120px;color:#fff;" value="Remove Question">
                <h3>Options</h3>
                <div class="options">
                <label>a.</label><input class="option optiona"><input onClick="setAnswer(this.parentNode.id, this.className)" type="radio" class="a" name="answer">&nbsp;
                <label>b.</label><input class="option optionb"><input onClick="setAnswer(this.parentNode.id, this.className)" type="radio" class="b" name="answer">
                <div class="clear"></div>
                <label>c.</label><input class="option optionc"><input onClick="setAnswer(this.parentNode.id, this.className)" type="radio" class="c" name="answer">&nbsp;
                <label>d.</label><input class="option optiond"><input onClick="setAnswer(this.parentNode.id, this.className)" type="radio" class="d" name="answer">
                </div>  
                </div>  

This can be seen live here:http://bit.ly/R8hB2m

  • 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-12T09:13:17+00:00Added an answer on June 12, 2026 at 9:13 am

    Start your copyAppendQ function with:

    copyAppendQ.id = (copyAppendQ.id || 0)+1;
    

    Then when assigning the ID:

    id = "questioncon"+copyAppendQ.id;
    

    This will ensure that you won’t get the same ID twice, even if questions are deleted.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.