Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#907 closed bug (fixed)

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.

Change History (7)

comment:1 Changed 13 years ago by joern

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"
} : {};

comment:2 Changed 13 years ago by aaron.heimli

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

comment:3 Changed 13 years ago by aaron.heimli

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

comment:4 Changed 13 years ago by brandon

This can also be used to fix bug #745

comment:5 Changed 13 years ago by brandon

Component: ajaxcore

comment:6 Changed 13 years ago by aaron.heimli

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.

comment:7 Changed 13 years ago by joern

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.

Note: See TracTickets for help on using tickets.