tags:

views:

80

answers:

2

Why? I have $('#someselector').html('<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;...');

<div id="someselector"></div>

I keep getting this nasty error:

uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://localhost:8888/cms/pages/js/1jquery.js :: anonymous :: line 12" data: no]

Line 0

Try this out:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
    <script type="text/javascript">
        var $html = "<html><body>jQuery sux</body></html>";
        $('#crap').html($html);
    </script>
  </head>
  <body>
      <div id="crap"></div>
  </body>
</html>
+3  A: 

The HTML code that you try to add is invalid. You can't add a whole HTML document inside another.

Guffa
it doesn't work with valid html either
syn4k
Try the test code I just added in the original bug
syn4k
You are still trying to add a whole HTML document inside another. Try something like `$('#crap').html('<div>just an HTML snippet</div>')`.
Guffa
Yes, I know that. I'm doing that on purpose. It is a requirement to store one html doc insdide a div
syn4k
Thanks all, I elected to manipulate the HTML in PHP rather than in the DOM
syn4k
@syn4k: That will get rid of the error message, but it still won't work properly. The browser will try to render the invalid HTML as well as it can, but the result is unpredictable.
Guffa
A: 

I agree, whole HTML document cannot be contained in another HTML doc. My idea would be is to contain your HTML document in an <iframe> tag. HTML iframe tag

samer
Good idea but iframe expects an html file as its source. I only have raw html that is generated by $.ajax() services
syn4k
@syn4k - You could use PHP to create a file with the required HTML, then, on another page, you can insert an `iframe` with jQuery and set its `src` to that of the PHP created file.
Peter Ajtai