Skip to main content

Bug Tracker

Side navigation

#9185 closed bug (invalid)

Opened May 09, 2011 08:21AM UTC

Closed May 09, 2011 02:21PM UTC

attr gives an unhandled error when run on a document selection

Reported by: lonesomeday Owned by:
Priority: low Milestone: 1.next
Component: attributes Version: git
Keywords: Cc:
Blocked by: Blocking:
Description

Before jQuery 1.6, it was possible (if silly) to get the properties of the document object using attr(). This functionality has obviously been broken in 1.6. However, it does not fail in a natural way (returning undefined?). It calls getAttribute on the node, which causes a JS error.

jsFiddle example

StackOverflow question

Attachments (0)
Change History (2)

Changed May 09, 2011 09:24AM UTC by lonesomeday comment:1

Github pull request -- make attr return undefined (as for comment and text nodes).

Changed May 09, 2011 02:21PM UTC by timmywil comment:2

component: unfiledattributes
priority: undecidedlow
resolution: → invalid
status: newclosed

As the docs now state (http://api.jquery.com/attr), attr should not be used on the document or window. It throws an error because these do not and cannot have attributes. Failing silently may not be as helpful.