> $("htmlstring") converts the HTML to DOM elements using the innerHTML
> property of a <div> element. That won't work if the string is an entire
> document, since an <html> element can't be a child of a <div> element.
True, that you won't get a full HTML document out, but with a little
pre-parsing you can at least get the very useful contents of the
<body> which is why I created the following method:
// Turns `$.get`/`$.ajax` responseText HTML document source into a
DOM tree,
// wrapped in a `<div/>` element for easy `.find()`ing
// Stripping out all nasty `<script>`s and such things.
getResultBody: function(responseText) {
//return $('<body/>').append( // <-- this seems to cause
crashes in IE8. (Note: Crash doesn't seem to happen on first run)
return $('<div/>').append(
$(responseText||[])
.not('script,title,meta,link,style')
.find('script,style')
.remove()
.end()
);
},
Ajax loading whole documents is *the* way to go, when "hijaxing"
ordinary <a href=""> links - for true, unobtrusive progressive
enhancements to websites.
--
Már
--
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=.