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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:07:20+00:00 2026-06-03T03:07:20+00:00

I am trying to dynamically append an HTML-snippet to an existing Element with .append

  • 0

I am trying to dynamically append an HTML-snippet to an existing Element with .append.

Somehow, the HTML String which was created by the script is not appended to the element.

The element which is appended to is not hooked into the DOM at the moment when the snippet is appended.

All of it is encapsulated in a JavaScript function. Here is the code:

append_content = function() {
    var elem = $('<li><div>some text</div></li>');
    var somecontent = get_content();  // returns a string: '<div>xx</div>'
    elem.append('<div>bleh1</div>');
    elem.append(somecontent);
    elem.append('<div>bleh2</div>');
    console.log(elem);
    return elem;
}

The log contains all items correctly, like:

<li>
    <div>some text</div>
    <div>bleh1</div>
    <div>xx</div>
    <div>bleh2</div>
</li>

But when im hooking the elem to the DOM later on, the content of the function call is gone. I.e. it is not visible in the computed source (neither in FireBug nor Chrome development tools).

It looks like this:

<li>
    <div>some text</div>
    <div>bleh1</div>
    <div>bleh2</div>
</li>

I am almost convinced that I have some scope issues or something like that here, but I don’t get it. There is no error message in the console. Any advice?

Update

Indeed, this was a self-made problem. Striipng down the code for an examle to post here made me realize that i called a similar function wihtout the function call mentioned above – silly me. Thanks for all the comments and 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-03T03:07:22+00:00Added an answer on June 3, 2026 at 3:07 am

    It looks correct to me – I’d check the output of the get_content() method to ensure it is in fact returning valid html. Check it using alert(“somecontent”) as well as console – console.log only writes out the first line of XML in firebug – not sure about chrome…

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

Sidebar

Related Questions

I am trying dynamically to append an <svg> element to an existing SVG island
I'm having issues trying to append dynamically created html inside a SimpleModal box (OSX
I am trying to dynamically load a JavaScript file by adding a script element
I'm trying to understand HTML elements that are dynamically created with JavaScript. Specifically can
I am trying to dynamically append some objects to a div and then programatically
I'm trying to dynamically create a connection string during compile time: private static string
I'm trying to dynamically spawn a video element on a page using JavaScript. JavaScript
I'm trying to make something where you can dynamically insert an HTML block, and
I'm creating a dropdown box dynamically in jQuery by appending html as follows: .append(<br><SELECT
I am trying to dynamically append where conditions into a single expression-object, then pass

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.