Tuesday, 15 June 2010

Jquery html() changes my code...? -



Jquery html() changes my code...? -

i getting html info $.ajax , need insert them in <div></div> in cases, returned html, needs contain div, reply like:

info here</div><div>info there

instead of closing 1st div, creates this:

<div>info here<div>info there</div></div>

how can prevent this?

this isn't valid html:

info here</div><div>info there

i uncertainty it's jquery doing this. more it's browser trying create sense of invalid markup, correcting best can. time encounters invalid markup, whether delivered via ajax or initial page load.

you can prevent happening using valid html.

edit: note in browser html page isn't raw string (like server-side code). it's hierarchical model of document elements. kind of string manipulation might server-side build html doesn't work same client-side. don't want break elements injecting strings between them. rather, replace contents of parent element. in existing div might insert:

$('#parentdiv').html('<div>info here</div><div>info there</div>');

or might replace entire parent div markup:

$('#parentdiv').replacewith('<div>info here</div><div>info there</div>');

jquery html ajax dom dynamic-content

No comments:

Post a Comment