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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:07:20+00:00 2026-06-10T06:07:20+00:00

I need to dynamically insert an element into an existing list of blog posts.

  • 0

I need to dynamically insert an element into an existing list of blog posts.

Here is an example of the HTML:

<div id="page">
  <div id="post">Post Content</div>
  <div id="post">Post Content</div>
  <div id="post">Post Content</div>
  <div id="post">Post Content</div>
  <!---- Dynamic Post Inserted Here--->
  <div id="post">Post Content</div>
  <div id="post">Post Content</div>
</div>

I’ve created a for loop that iterates through the posts and returns the location, but the location returned is an integer so I can’t append the new post to that variable. So what is the best way to append the item to my current post list?

I don’t have the exact function in front of me but this is essentially what i’m doing:

var post = docuemnt.getElementById('post');
var page = docuemnt.getElementById('page');
var pc = 0;
var insert = 5;
var newPost = "new post content";

for(post in page){
  if(pc == insert){
    **append new post content after this post**
  }else{
  pc++;
  }
}
  • 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-10T06:07:21+00:00Added an answer on June 10, 2026 at 6:07 am

    If you were using jQuery, this would be incredibly easy.

    $('#post4').after('<div id="post5">new post content</div>');
    

    If you want to do it in pure JavaScript, then take a look at this question. The basic idea is:

    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
    

    In your case, you’d need to create a div node and append to the document directly.

    var newpost = document.createElement('div');
    newpost.id = 'post5';
    newpost.innerText = newpost.textContent = "new post content";
    
    var post = document.getElementById('post4');
    
    post.parentNode.insertBefore(newpost, post.nextSibling);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within a particular div/span that I might dynamically insert into the DOM, I need
I need to dynamically insert an image in my JS code. In my Razor
I need to dynamically build a list of textboxes using javascript and jquery. The
I need to dynamically load banner images into a HTML5 app and would like
I have a situation where I need to dynamically build up a list of
Here's my issue - I need to dynamically download several scripts using jQuery.getScript() and
I'm using Qwebkit and I like to be able to insert into html table
In my .net mvc application, I need to dynamically insert contents from local files
i need your help.I need to insert data dynamically but insertion should be from
I am trying to create a simplified code to insert images dynamically into a

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.