Opened 13 years ago
Closed 13 years ago
#6380 closed bug (invalid)
newline between DOCTYPE and root element when using $(xxx).html() causes unexpected behaviour
Reported by: | bgriffin | Owned by: | |
---|---|---|---|
Priority: | Milestone: | 1.4.3 | |
Component: | core | Version: | 1.4.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
This was originally posted at http://forum.jquery.com/topic/newline-between-doctype-and-root-element-when-using-xxx-html-causes-unexpected-behaviour . My assumption has been that due to no obvious flaw in the proposal, this is indeed a bug.
The effect is that a valid xhtml fragment is not easily accessible via the jquery api when it has whitespace between the DOCTYPE and the root element in JQuery 1.4.2.
The problem is manifest (tested) on the following browsers: Windows Chrome 4.1,Windows Firefox 3.6.2,MacOS X Firefox 3.5.8,MacOS X Safari 4.05.
Note that on Windows IE 7 ,Windows IE 7 neither fragments are correctly displayed.
Three files are used to demonstrate this problem (see attachment). The core code is as follows, and jquery is not behaving as expected for the loldiv.html text, which is a legal xhtml fragment; namely the 'loldiv' fragment is not being 'appended' into the div class='o' of the base document, and the html() accessor cannot correctly parse the jQuery object constructed from the loldiv.html xhtml.
lildiv.html has no ws between DOCTYPE and document element (no fail) loldiv.html has ws between DOCTYPE and document element (fails) var urli="lildiv.html", urlo="loldiv.html"; $.get(urli,function(data){ loadPanel(data,"div.i"); }) $.get(urlo,function(data){ loadPanel(data,"div.o"); }) function loadPanel(data,point) { $(point).append($(data).html()); }
Attachments (4)
Change History (5)
Changed 13 years ago by
Attachment: | jqproblem.zip added |
---|
comment:1 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Sorry but that is in browser-dependent territory.
This method uses the browser's innerHTML property. Some browsers may not return HTML that exactly replicates the HTML source in an original document. For example, Internet Explorer sometimes leaves off the quotes around attribute values if they contain only alphanumeric characters.
jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.
Three tiny html files that demonstrate the problem.