Skip to main content

Bug Tracker

Side navigation

#907 closed bug (fixed)

Opened February 01, 2007 08:22PM UTC

Closed February 05, 2007 08:20PM UTC

Last modified June 20, 2007 01:53AM UTC

Don't apply fixes in attr for XML documents

Reported by: joern Owned by:
Priority: major Milestone:
Component: core Version:
Keywords: Cc:
Blocked by: Blocking:
Description

The following code can be used to detect if an element is in a normal document:

if ( element.ownerDocument.body ) {
  // This is an HTML document
}

With that, fixes like for - forClass and class - className can be avoided in XML documents.

Attachments (0)
Change History (7)

Changed February 01, 2007 08:24PM UTC by joern comment:1

Like this?

// don't apply fix to xml documents
var fix = elem.ownerDocument.body ? {
	"for": "htmlFor",
	"class": "className",
	"float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
	cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
	innerHTML: "innerHTML",
	className: "className",
	value: "value",
	disabled: "disabled",
	checked: "checked",
	readonly: "readOnly",
	selected: "selected"
} : {};

Changed February 02, 2007 01:37AM UTC by aaron.heimli comment:2

If you try this code on this page (using firebug or any JavaScript console)

jQuery("p")[0].ownerDocument.body

you'll see that it returns the <body> element, so I don't think that quite works

Changed February 02, 2007 07:50AM UTC by aaron.heimli comment:3

D'oh! Forget my last comment, I misread Joern's example!

It seems to work fine in every browser except IE 5.5 (couldn't test Safari), where HTML elements don't seem to have an ownerDocument property (XML elements do, though).

Test page: http://aheimlich.freepgs.com/tests/jquery/htmlelem-or-xmlelem/

I guess you could do

!elem.ownerDocument || elem.ownerDocument.body

but I don't know how Safari would react to that

Changed February 02, 2007 03:51PM UTC by brandon comment:4

This can also be used to fix bug #745

Changed February 02, 2007 07:10PM UTC by brandon comment:5

component: ajaxcore

Changed February 02, 2007 09:34PM UTC by aaron.heimli comment:6

I got the chance to test my IE 5.5 workaround on Safari 2.0.3 and it didn't seem to cause any problems. If someone can test this on Safari 1, then I think we have a solution.

Changed February 05, 2007 08:20PM UTC by joern comment:7

resolution: → fixed
status: newclosed

Fixed in revision 1286. Unfortuanetely, the href bug is another story. getAttribute("href", 2) simply doesn't work, it returns the absolute URL every time.

I hope we get the refactoring for attr/css at some point, I had to check for element.tagName once more.