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

  • Home
  • SEARCH
  • 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 7247915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:04:09+00:00 2026-05-28T22:04:09+00:00

I created a DOM fragment using JQuery: var $content = $(<div /, {id:content}) I

  • 0

I created a DOM fragment using JQuery:

var $content = $("<div /", {id:"content"})

I want to output the fragment as a string, so I attempted:

$content.html();

That returns an empty string, because there are no children. How can I return a string containing:

<div id="content" />
  • 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-05-28T22:04:10+00:00Added an answer on May 28, 2026 at 10:04 pm

    jQuery doesn’t have anything in its API to do this directly, but you can use the native .outerHTML property.

    $content[0].outerHTML
    

    …but Firefox doesn’t support this, so you can do something like this…

    $content[0].outerHTML || $('<div>').append($content.clone()).html();
    

    http://jsfiddle.net/m22fn/

    Note that a <div> tag doesn’t self-close.

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

Sidebar

Related Questions

I have a div that is filled by JS created DOM elements, I want
I'm using jQuery Tools ( http://flowplayer.org/tools/index.html ) to create tooltips, I've created a js-file
I'm creating DOM elements dynamically (more specifically, using jQuery to create a DIV containing
I have HTML in a JavaScript string (containing usual, nested HTML). Using jQuery, can
I have an html text fragment that's part of the page's DOM that I
Consider following DOM fragment: <div id=div-1>foo</div> <div id=div-2>bar</div> Is it possible to insert HTML
I want to retrieve all objects (not DOM elements) of a given type created
I am trying to load a xml document I created using PHP and DOM
I just appended some html to another JQuery object. I want to get a
I have a text string i'm trying to select the spans from using jQuery.

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.