You could also try changing <frag> to <div class="frag"> instead.  For
example this worked in firefox but not IE:

<body>
<script src="jquery.js"></script>
<frag>
   <div class=citybox><h2 class=citytitle>City of London</h2><p
class=desc>London is on the River Thames</p></div>
</frag>
<hr/>
<div id="myid"></div>
<script>
var frag = $("frag").children();
$("#myid").after(frag);
</script>
</body>

When I switched frag to span, for example, it worked.

On Jan 27, 7:29 am, JS London <jus...@alphainitiatives.com> wrote:
> Hi,
>
> I would like to pass an fragment of HTML as a field in my Ajax
> response and then insert this into the DOM. For example if part of the
> Ajax XML response (ajax_xml) is as follows:
>
> <cityid>2</cityid>
> <frag>
>    <div class=citybox><h2 class=citytitle>City of London</h2><p
> class=desc>London is on the River Thames</p></div>
> </frag>
>
> (I want to generate the fragment markup server-side for consistency.)
>
> I can extract the HTML fragment as follows:
>
> var frag=$(ajax_xml).find("frag").children();
>
> But when I come to insert it into the DOM, neither of these work:
>
> a. $("#myid").after(frag);
> b. $("#myid").after($(frag).html());
>
> (it states in the JQuery website documentation that (b) will not work)
>
> Is there a way of doing this without having to escape the original
> HTML fragment? (which I want to avoid)
>
> Any help much appreciated, many thanks
> JS, London

Reply via email to