Bug Tracker

Modify

Ticket #6380 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

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

Change History

Changed 3 years ago by bgriffin

Three tiny html files that demonstrate the problem.

Changed 3 years ago by bgriffin

lildiv xhtml fragment

Changed 3 years ago by bgriffin

loldiv xhtml fragment

Changed 3 years ago by bgriffin

jquery instance

comment:1 Changed 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.