Bug Tracker

Opened 10 years ago

Closed 9 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)

jqproblem.zip (2.3 KB) - added by bgriffin 10 years ago.
Three tiny html files that demonstrate the problem.
lildiv.html (138 bytes) - added by bgriffin 10 years ago.
lildiv xhtml fragment
loldiv.html (139 bytes) - added by bgriffin 10 years ago.
loldiv xhtml fragment
jqueryproblem.html (807 bytes) - added by bgriffin 10 years ago.
jquery instance

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by bgriffin

Attachment: jqproblem.zip added

Three tiny html files that demonstrate the problem.

Changed 10 years ago by bgriffin

Attachment: lildiv.html added

lildiv xhtml fragment

Changed 10 years ago by bgriffin

Attachment: loldiv.html added

loldiv xhtml fragment

Changed 10 years ago by bgriffin

Attachment: jqueryproblem.html added

jquery instance

comment:1 Changed 9 years ago by dmethvin

Resolution: invalid
Status: newclosed

Sorry but that is in browser-dependent territory.

http://api.jquery.com/html/

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.

http://api.jquery.com/load/

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.

Note: See TracTickets for help on using tickets.