Skip to main content

Bug Tracker

Side navigation

#10757 closed bug (invalid)

Opened November 11, 2011 10:55AM UTC

Closed November 14, 2011 03:19PM UTC

Last modified March 14, 2012 10:58AM UTC

attr(): on XML documents returns "undefined"

Reported by: Thomas Scheffler Owned by: Thomas Scheffler
Priority: low Milestone: None
Component: attributes Version: 1.7
Keywords: Cc:
Blocked by: Blocking:
Description

After updating from 1.6.2 to 1.7 I noticed a bug. I load a XML document via AJAX request and process it via some jQuery methods, but attr() does not return a value anymore.

While

groups[i].getAttribute("USE")

returns "MASTER"

jQuery(groups[i]).attr("USE")

returns undefined

in 1.6.2 the jQuery code gave the same result as the DOM only code: "MASTER"

groups[i] is a XML element node.

Attachments (0)
Change History (4)

Changed November 11, 2011 05:04PM UTC by timmywil comment:1

component: unfiledattributes
owner: → Thomas Scheffler
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

Changed November 14, 2011 11:36AM UTC by Thomas Scheffler comment:2

status: pendingnew

Here is a minimal testcase. jQuery Edge is still broken, while 1.6.4 works fine

http://jsfiddle.net/TtPBn/

There is a problem with document.importNode(). If I skip that it works fine on Mozilla, but for cross browser support this call is needed.

Changed November 14, 2011 01:47PM UTC by dmethvin comment:3

I'll let timmywil weigh in on this, but I'll observe that by calling document.importNode on the element you've changed it from an XML node to an HTML one.

Changed November 14, 2011 03:19PM UTC by timmywil comment:4

resolution: → invalid
status: newclosed

Dave hit it on the nose. It works fine if importNode is not used to convert it: http://jsfiddle.net/timmywil/TtPBn/1/

The problem is that it is actually invalid to have uppercase attributes on html nodes. When attached to an html doc using importNode, the xml node becomes an invalid html node and the attribute names do not get lowercased as one may expect. As of 1.7, we always lowercase the name (which mostly helps with attributes like contentEditable where people don't always realize that the attribute should be retrieved with "contenteditable").

For reference, see the note in the spec

I recommend not using importNode as that's not what it is meant for anyway. https://developer.mozilla.org/en/DOM/document.importNode