1

I want to get all content of a div using jquery.

<div id="load_template_data" style="border:1px solid #000000;  width:100%;">

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml">

  <head>
  ...my stuff
  </head>
  <body>
  ..my other stuff
  </body>
  </html>

  </div>

but when I use jquery function

 `var editor_data = $('#load_template_data').html();
    alert(editor_data);`

 'alert(editor_data);'  

retrun me only div tags,means only html, not return <head></head> <body></body></html>

so I use `var editor_data = $("#load_template_data").contents();

    alert(editor_data);`

but this return [object Object] I want to get all data from this div.perhaps I am missing anything.

Muhammad Shahzad
  • 9,340
  • 21
  • 86
  • 130
  • 3
    Unless that's inside an iframe it doesn't look like valid HMTL. – elclanrs May 24 '13 at 07:06
  • If you're trying to get the entire page, see: http://stackoverflow.com/questions/866073/get-entire-content-of-page – naththedeveloper May 24 '13 at 07:08
  • If you're making an 'editor' you need to edit _escaped_ html. You can't have `` tags in a div. Another option is to use a ` – Benjamin Gruenbaum May 24 '13 at 07:08
  • @FDL,@Benjamin, inside the div `
    ` tags.hope you get my point.
    – Muhammad Shahzad May 24 '13 at 07:23
  • @elclanrs , I am not using iframe,only div and contain a wep page template. – Muhammad Shahzad May 24 '13 at 07:48
  • You should consider re-evaluating what youre doing here. You will run into all kinds of trouble with this very invalid html. At least try to get only the contents of the body tag of the injected page BEFORE you inject it into your main page. Then you can get the proper contents and not crash the browser on the way ;) – ToBe May 24 '13 at 08:08

1 Answers1

1

These are content related tags. So you can get this with data

<table>
<tr>
<td>
<div>
<span>
<a>
<link>
<img>

But these are HTML syntax tags. So you can't get this tags

<!DOCTYPE>
 <HTML>
 <head>
 <body>
PonrajPaul
  • 174
  • 1
  • 7
  • 18