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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:35:02+00:00 2026-06-18T17:35:02+00:00

Given var html = <html><body><p>Hello, World!</p><p>Ciao!</p></body></html>; I would like to extract the inner HTML

  • 0

Given

var html = "<html><body><p>Hello, World!</p><p>Ciao!</p></body></html>";

I would like to extract the inner HTML of the body tag (<p>Hello, World!</p><p>Ciao!</p>).

.find() finds the body DOM node

var body = $(html).find("body");

but I cannot find a means to get the inner HTML of that node. I tried:

var text = body.text(); //  returns ""
var var = body.var(); // returns undefined

How can I get a string representation of the <body> tag’s inner HTML?

  • 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-18T17:35:03+00:00Added an answer on June 18, 2026 at 5:35 pm

    jQuery will strip the html and body tags out when you wrap the string in $().

    Therefore you can do this:

    var str=$('<div>').append($(html)).html()
    

    DEMO http://jsfiddle.net/LxdrM/

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

Sidebar

Related Questions

Given the following HTML page: <html> <head> <title>WatiN Test</title> </head> <body> <div> <p>Hello World!</p>
If I run this code - var html= '<html><head></head><body><div class=bar></div></body></html>'; console.log($(html).find('div')); I get no
Given HTML like this: <body> <form name=myForm action=savedata.php method=post> <input type=text name=myName /> </form>
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
Given a datasource like that: var c = new Car[] { new Car{ Color=Blue,
<html> <head> <title>Greatest of three</title> </head> <body> <script type=text/javascript> var a = parseInt(prompt(Enter A));
How can I replace this character | in JavaScript? <html> <body> <script type=text/javascript> var
Given the following: $(document).ready(function() { $('a.went-cold-turkey').click(function() { $(body).css(cursor, progress); var activity_day = this.rel; $.ajax({
Given the following html code: <body onload=loadSett()> <form id=settingsForm name=settingsForm> <select name=Sound id=Sound> <option
function superman(){ //some code var opitem = $(#opinionitem).html(); opitem.replace(:opinionid,valid string); //more code } gives

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.