Bug Tracker

Opened 8 years ago

Closed 8 years ago

#9751 closed bug (invalid)

.attr('class') returns undefined instead of blank

Reported by: tryandls Owned by:
Priority: low Milestone: 1.next
Component: attributes Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:

Description

In previous versions, calling .attr('class') on an element with no class attribute (not one with class="") returned blank. It now returns undefined.

This has the potential to break code, for example something like $('#foo').attr('class').indexOf('bar').

Other than issue #9468, I can't find any mention of this issue. Tested only in FF4.

Change History (2)

comment:1 Changed 8 years ago by tryandls

Test Case http://jsfiddle.net/tryandls/HmUh6/1/

Same results in IE8

comment:2 Changed 8 years ago by timmywil

Component: unfiledattributes
Priority: undecidedlow
Resolution: invalid
Status: newclosed

This is due to a fix in attr in 1.6 as that is the intended behavior. It should return the attribute value or undefined if the attribute is not present on the element.

Note: See TracTickets for help on using tickets.