Side navigation
#7203 closed bug (wontfix)
Opened October 15, 2010 03:36PM UTC
Closed January 10, 2011 09:48PM UTC
Last modified March 13, 2012 08:57PM UTC
Unable to set `type` on button using attr()
Reported by: | RSMerrill@cc.usu.edu | Owned by: | |
---|---|---|---|
Priority: | high | Milestone: | 1.5 |
Component: | attributes | Version: | 1.5 |
Keywords: | Cc: | dmethvin, rwaldron | |
Blocked by: | Blocking: |
Description
While working with buttons I noticed that I cannot explicitly set the type of a button using the jQuery attr().
Demonstration of bug with setting the type on a button element:
http://jsfiddle.net/Zoramite/9p9F4/2/
On all the buttons the type should be button.
Attachments (0)
Change History (16)
Changed October 15, 2010 03:44PM UTC by comment:1
status: | new → open |
---|
Changed October 15, 2010 05:01PM UTC by comment:2
I updated the sample:
http://jsfiddle.net/Zoramite/9p9F4/3/
Test using the Static Button Normal JS
button.
Testing in Chrome 8.0.552.0 dev on Ubuntu 10.10:
this.type = 'button';
- Does not change typethis.setAttribute('type', 'button');
- Changes type to button
Testing in FF 3.6.10 on Ubuntu 10.10:
this.type = 'button';
- Changes type to buttonthis.setAttribute('type', 'button');
- Changes type to button
Changed October 15, 2010 07:10PM UTC by comment:3
Updated test again:
http://jsfiddle.net/Zoramite/9p9F4/4/
In IE 8.0.6001.18702 on Windows XP:
this.type = 'button';
- Throws an errorthis.setAttribute('type', 'button');
- Changes type to button
In Chrome 8.0552.0 dev on Windows XP:
this.type
= 'button'; - Changes type to buttonthis.setAttribute('type', 'button');
- Changes type to button
In Safari 5.0.2 on Windows XP:
this.type
= 'button'; - Changes type to buttonthis.setAttribute('type', 'button');
- Changes type to button
In Opera 10.62 on Windows XP
this.type
= 'button'; - Changes type to buttonthis.setAttribute('type', 'button');
- Changes type to button
Changed October 15, 2010 07:20PM UTC by comment:4
Older IE does not allow changing the
typeon a
button, for consistency we have been throwing an error on all platforms since 1.4, and still should be in 1.4.3:
http://github.com/jquery/jquery/blob/master/src/attributes.js#L298
So...why aren't we seeing an error with the test case?
Changed October 15, 2010 07:50PM UTC by comment:5
So my last set of tests were flawed. The html was specifying the type of button initially.
Updated test:
http://jsfiddle.net/Zoramite/9p9F4/5/
Results:
Testing in Chrome 8.0.552.0 dev on Ubuntu 10.10:
- Defaults to
submit
type this.type = 'button';
- Does not change typethis.setAttribute('type', 'button');
- Changes type to button
Testing in FF 3.6.10 on Ubuntu 10.10:
- Defaults to
submit
type this.type = 'button';
- Changes type to buttonthis.setAttribute('type', 'button');
- Changes type to button
Testing in IE 6.0.2900 on Windows XP:
- Defaults to
button
type this.type = 'button';
- Throws an Errorthis.setAttribute('type', 'button');
- Changes type to button- When using html with
type="submit"
it does not change type usingsetAttribute()
Testing in IE 7.0.5730.13 on Windows XP:
- Defaults to
button
type this.type = 'button';
- Throws an Errorthis.setAttribute('type', 'button');
- Changes type to button- When using html with
type="submit"
it does not change type usingsetAttribute()
Testing in IE 8.0.6001.18702 on Windows XP:
- Defaults to
submit
type this.type = 'button';
- Throws an Errorthis.setAttribute('type', 'button');
- Changes type to button
Testing in Chrome 8.0552.0 dev on Windows XP:
- Defaults to
submit
type this.type = 'button';
- Does not change typethis.setAttribute('type', 'button');
- Changes type to button
Testing in Safari 5.0.2 on Windows XP:
- Defaults to
submit
type this.type = 'button';
- Does not change typethis.setAttribute('type', 'button');
- Changes type to button
Testing in Opera 10.62 on Windows XP
- Defaults to
submit
type this.type = 'button';
- Changes type to buttonthis.setAttribute('type', 'button');
- Changes type to button
Testing in FF 3.6.10 on Windows XP
- Defaults to
submit
type this.type = 'button';
- Changes type to buttonthis.setAttribute('type', 'button');
- Changes type to button
Changed October 15, 2010 07:53PM UTC by comment:6
So, from the limited testing that I have done, it looks like the IE6 and IE7 are the ones that do not allow the setAttribute()
to change the type.
In my specific case that is fine since it defaults to button
on those two versions.
But in general it would not work on those so it should probably through the error to keep things across all browsers consistent.
Changed October 21, 2010 11:00PM UTC by comment:7
milestone: | 1.4.4 → 1.4.5 |
---|
Retargeting due to severity of regressions in 1.4.3.
Changed November 03, 2010 02:11AM UTC by comment:8
Whether jQuery throws an error or not, it is not possible to change the
typeof a button cross-browser because IE won't allow it. Any end-user code needs to be written with that in mind. I am thinking jQuery needs to go back to just setting the attribute and letting IE throw whatever fit it wants, rather than trying to special-case this.
Changed November 08, 2010 07:14AM UTC by comment:9
cc: | → dmethvin, snover, rwaldron |
---|
I agree with dmethvin on this one. As it isn't possible for us to cater for cross-browser type-setting in this case we should allow IE to throw the error MS deems best for this type of situation (unless we just want to throw one ourselves). Thoughts?
Changed November 08, 2010 05:26PM UTC by comment:10
component: | unfiled → attributes |
---|---|
priority: | undecided → high |
+1 to dmethvin
Changed November 08, 2010 05:28PM UTC by comment:11
cc: | dmethvin, snover, rwaldron → dmethvin, rwaldron |
---|
Changed January 10, 2011 09:34PM UTC by comment:12
This bug is relevant to my interests.
Changed January 10, 2011 09:48PM UTC by comment:13
resolution: | → wontfix |
---|---|
status: | open → closed |
To quote dmethvin, "Whether jQuery throws an error or not, it is not possible to change the type of a button cross-browser because IE won't allow it."
Changed January 31, 2011 05:53PM UTC by comment:14
version: | 1.4.3 → 1.5 |
---|
There wasn't a 1.4.5 release, was actually 1.5.
Changed January 31, 2011 05:54PM UTC by comment:15
milestone: | 1.4.5 → 1.5 |
---|
There was no 1.4.5 release, was actually 1.5.
Changed June 27, 2011 06:20PM UTC by comment:16
I just stumbled upon this issue while working on a project that does not include jQuery, but is still relevant to this case. We do not support IE6 but we do support IE7 so a fix was needed. The fix: set the form button as type="button" and let IE7 default to this type. Then add a click event that submits the parent form. Then handle the form submit event however you like!
A workaround for this would be replacing the actual HTML content for the button or container for the button itself.
Just out of interest, is switching the form element type something you have attempted without using jQuery? I haven't actually seen this attempted before so I'm wondering if its the case that this may not be possible.
Leaving open in case there are further thoughts or comments that can contribute.