Skip to main content

Bug Tracker

Side navigation

#6380 closed bug (invalid)

Opened March 31, 2010 09:59AM UTC

Closed July 21, 2010 02:23AM UTC

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:

This was originally posted at . 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)
  • (2.3 KB) - added by bgriffin March 31, 2010 10:00AM UTC.

    Three tiny html files that demonstrate the problem.

  • jqueryproblem.html (0.8 KB) - added by bgriffin March 31, 2010 10:04AM UTC.

    jquery instance

  • lildiv.html (0.1 KB) - added by bgriffin March 31, 2010 10:01AM UTC.

    lildiv xhtml fragment

  • loldiv.html (0.1 KB) - added by bgriffin March 31, 2010 10:02AM UTC.

    loldiv xhtml fragment

Change History (1)

Changed July 21, 2010 02:23AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

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.