You could do it this way: http://docs.jquery.com/Ajax/load
You can pass a selector to load() to pick what you want from the response. 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