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

The Archive Base Latest Questions

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

I have dynamically generated html thru ajax when a page is loading, something like

  • 0

I have dynamically generated html thru ajax when a page is loading, something like this,

Dynamically inserted,

<p class="Hello">
  <span id='click lvl1'>1</span>
  <span>2</span>
</p>

Now, I am trying to add another node into my <p> element. Again, dynamically thru ajax.

Server response is something like,

<p class="Hello lvl2">
  <span id='click'>1</span>
  <span>2</span>
</p>

Which I want to insert into the element which I have got first time.

final result,

<p class="Hello">
  <span id='click'>1</span>
  <span>2</span>
  <p class="Hello lvl2">
   <span id='click'>1</span>
   <span>2</span>
  </p>
</p>

While making an second ajax call I am getting reference to <span id='click lvl1'>1</span> element.


What have I tried so far?

Everthing, I could try I have tried but I am not able to inset the node. I am assuming that I am doing something really wrong. My attempts are,

pElement is <span id='click'>1</span>

  1. pElement.parent().appendChild(data.expandTreeVal);
  2. pElement.parent().append(data.expandTreeVal);
  3. pElement.parent().after(data.expandTreeVal);
  4. pElement.parentNode().appendChild(data.expandTreeVal);

Debugging

Do I really get anything from server?

Yes, When I do alert(data.expandTreeVal); it shows me my desired HTML.

any thoughts will be a great help.

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

    You can only append DOM elements to an element, you can’t append HTML code in a string.

    Create an element, use the innerHTML method to put the HTML code in it, then get the first child node from it to get the p element as a DOM element.

    var div = document.createElement('DIV');
    div.innerHTML = data.expandTreeVal;
    var p = div.childNodes[0];
    

    Then you can add it to the document using the parentNode and appendChild methods:

    pElement.parentNode.appendChild(p);
    

    Demo: http://jsfiddle.net/AfVfE/

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

Sidebar

Related Questions

I have some static html content (included on a dynamically generated page) that I
I have a dynamically generated html page which is designed to be printed. I
Have JSP page with dynamically generated HTML table with unknown number of rows. Have
I have a simple ASPX page that renders a dynamically generated HTML table to
Essentially, I have a dynamically generated local HTML form that I would like to
How do I serve a dynamically generated image in Django? I have an html
html code meta tag description, it is generated dynamically and we have quotes in
I have dynamically generated strings like @#@!efq@!#! , and I want to remove specific
Fiddle: http://jsfiddle.net/MhWm5/16/ I have some dynamically generated table rows/values with dynamic IDs <td class=control-group>
I'm working on a web page where I have a dynamically generated table where

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.