jquery-pjax
jquery-pjax copied to clipboard
avoid lossing body when parsing html
- as http://api.jquery.com/jQuery/#jQuery2 stats, the parsing process
may strip
bodyelement, and return children ofbodyinstead of body. And this happens in most modern browsers (Chrome / Firefox latest releases).
When passing in complex HTML, some browsers may not generate a DOM that
exactly replicates the HTML source provided. As mentioned, jQuery uses
the browser"s .innerHTML property to parse the passed HTML and insert
it into the current document. During this process, some browsers filter
out certain elements such as <html>, <title>, or <head> elements. As
a result, the elements inserted may not be representative of the
original string passed.
- Also fixed the corresponding unit test.
Why do you need the body?
hi @staabm , because parseHTML's expected behaviour is to convent an HTML string into an element, not stripping the container element . In other way, not to get innerHtml, but the outterHtml. Stripping the container element (parent), will be done later ( https://github.com/layerssss/jquery-pjax/blob/48c17bb1846b4ebae6d1d4b36777998129737248/jquery.pjax.js#L651 ).
Interesting. I'm not sure about this implementation but I need to investigate that original claim about losing the <body> element.