Skip to main content

Bug Tracker

Side navigation

#9284 closed bug (worksforme)

Opened May 14, 2011 06:45AM UTC

Closed May 14, 2011 02:54PM UTC

Last modified May 14, 2011 06:51PM UTC

.attr('checked', 1) throws exception

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

Calling .attr() with 2nd argument of type Number throws "TypeError: Object 1 has no method 'toLowerCase'". There's no such problem when using .prop().

Attachments (0)
Change History (7)

Changed May 14, 2011 09:44AM UTC by addyosmani comment:1

component: unfiledattributes
owner: → alec
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsFiddle.net that reproduces the issue experienced to help us assess your ticket!

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

Changed May 14, 2011 12:33PM UTC by miketaylr comment:2

Why would you pass .attr() a number and not a string?

Changed May 14, 2011 02:54PM UTC by addyosmani comment:3

resolution: → worksforme
status: pendingclosed

Agreed with miketaylr, however:

Tested with jQuery (edge) here http://jsfiddle.net/ez57B/3/ across Chrome latest, Firefox 4, Opera, IE6 and IE8. All of these browsers had no problem at all setting the checked value using a number rather than a string with no exception experienced.

Please ideally use the string version instead regardless as we haven't documented a number functioning correctly for 'checked' values.

Changed May 14, 2011 06:11PM UTC by alec comment:4

I don't know what is edge, I'm using 1.6.1 uncompressed and the error is in line 2196 : "value.toLowerCase is not a function". prop() is working fine with this. Also documentation says nothing about expected argument type. Some users are using 1/0 as boolean states, and it works with object properties like checked, so maybe you should handle this properly.

Changed May 14, 2011 06:14PM UTC by alec comment:5

Changed May 14, 2011 06:27PM UTC by timmywil comment:6

It may work now, but your call does not make sense. You can do .attr("checked", "checked"), .attr("checked", true), .prop("checked", true), or simply elem.checked = true. No numbers should be involved here.

Changed May 14, 2011 06:51PM UTC by alec comment:7

Right, but elem.checked = 1 works too, isn't it? No matter, it's fixed now.