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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:41:51+00:00 2026-06-14T04:41:51+00:00

I would like to append some html to a div when a button is

  • 0

I would like to append some html to a div when a button is clicked. The only thing that needs to be dynamic about it is that it needs to have a different id the the otherwise identical html above it. So if I have a structure like this:

<div id="container">
   <div id="div1" class="inner">
       <p id="P1">Some content</p>
   </div>
   <div id="div2" class="inner">
       <p id="P2">Some content</p>
   </div>
</div>

and to the end of container i would like to append

  <div id="div3" class="inner">
         <p id="P3">Some content</p>
  </div>

What would be a good method to store this HTML? Keep it all in a php page and post the number the new div’s id should be incremented to? Or is is smarter to put the html inside a string, and have a regular expression increment all of the numbers. Or is there some incredibly obvious way to do this that I’ve completely missed.

Jquery is an option, as that’s already on the page.

Also, if this question seems too open-ended, please let me know in the comments how I can change it before closing it.

Thank you very much.

  • 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-14T04:41:52+00:00Added an answer on June 14, 2026 at 4:41 am

    Based on your answers to comments so far (i.e. that the id’s aren’t really important, and that you will have input elements in the content), I would say that you would want to redo your html to look like this:

    <div id="container">
       <div class="inner">
           <p><input type="text" name="order_item[]" value="" /></p>
       </div>
       <div class="inner">
           <p><input type="text" name="order_item[]" value="" /></p>
       </div>
    </div>
    

    Note there are no longer id’s and I have used array notation for your input elements such that they will be posted as an array to the receiving script (eliminating the need to increment counters in javascript or parse different posted variable names into a usable array in PHP on the server).

    And then use something like this in jQuery

    $('#button_id').click(function() {
        $('#container > div.inner:last').clone().val('').appendTo('#container');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like some container that I can very efficiently append a variable amount
I have an existing XML file that I would like to append without changing
I would like to transfer some content from (div class=StaffBlock) that loaded from the
If I have html like so: <div> <span></span> <span></span> <span></span> </div> How would I
I have to append, some text to another field when a image is clicked.
Within a TagHandler which I passed to Html.fromHtml() , I would like to append
I need to append html content to a table some content that's returned from
I have a simple button in HTML like this: <input type='button' id='btnPrint' value='Print' onclick=changeStylesheet();
Originally I would like to transfer some content (div class=StaffBlock) which is loaded from
I would like to append some code to a page using jQuery/jQuery mobile, but

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.