0

I know how to grab html inside the body tag and I can do that by

$("body").html();

The above line return me the html which is inside the body tag. But I want the html inclidung the body tag. For example

<body attr1="abc" attr2="def" attr3="xyz">
    <div class="container">
         I am in trouble.Please HELP me!!
    </div>
</body>

I want something which returns me the html along with the body tag and all its attributes. How can I achieve that ??

Yunus Aslam
  • 2,447
  • 4
  • 25
  • 39

2 Answers2

0

You can get outerHTML using:

$('body')[0].outerHTML

Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0
outrHTML - the thing you need here

MDN defination - The outerHTML attribute of the element DOM interface gets the serialized HTML fragment describing the element including its descendants. It can be set to replace the element with nodes parsed from the given string.

so the code will be

$("body")[0].outerHTML

or pure javascript

document.body.outerHTML
Ranjit Singh
  • 3,715
  • 1
  • 21
  • 35