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 comment:1
component: | unfiled → attributes |
---|---|
owner: | → alec |
priority: | undecided → low |
status: | new → pending |
Changed May 14, 2011 12:33PM UTC by comment:2
Why would you pass .attr() a number and not a string?
Changed May 14, 2011 02:54PM UTC by comment:3
resolution: | → worksforme |
---|---|
status: | pending → closed |
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 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 comment:5
I've found this commit https://github.com/jquery/jquery/commit/cf702496ee28830f3488ed3f1c3940cfbb2dfa8f which probably fixed this.
Changed May 14, 2011 06:27PM UTC by 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 comment:7
Right, but elem.checked = 1 works too, isn't it? No matter, it's fixed now.
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.