Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#9284 closed bug (worksforme)

.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:


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

Change History (7)

comment:1 Changed 8 years ago by addyosmani

Component: unfiledattributes
Owner: set to 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.

comment:2 Changed 8 years ago by miketaylr

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

comment:3 Changed 8 years ago by addyosmani

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.

comment:4 Changed 8 years ago by alec

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.

comment:5 Changed 8 years ago by alec

comment:6 Changed 8 years ago by timmywil

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.

comment:7 Changed 8 years ago by alec

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

Note: See TracTickets for help on using tickets.