aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Aaron <brandon.aaron@gmail.com>2009-03-17 22:27:25 +0000
committerBrandon Aaron <brandon.aaron@gmail.com>2009-03-17 22:27:25 +0000
commite73990a566fcb2dac71e1a25ec83382645adc5b7 (patch)
tree84990cb2f4a7c0d9a2c67ea9046ed04d47358d19
parentaabf635cfe9b75fce3d96eb3e40e25f4a29ea99b (diff)
downloadjquery-e73990a566fcb2dac71e1a25ec83382645adc5b7.tar.gz
jquery-e73990a566fcb2dac71e1a25ec83382645adc5b7.zip
fix for #3688, setting type attribute on button causes IE to throw error
-rw-r--r--src/core.js2
-rw-r--r--test/index.html2
-rw-r--r--test/unit/core.js12
3 files changed, 13 insertions, 3 deletions
diff --git a/src/core.js b/src/core.js
index 446c82e58..271e7c434 100644
--- a/src/core.js
+++ b/src/core.js
@@ -1004,7 +1004,7 @@ jQuery.extend({
if ( name in elem && notxml && !special ) {
if ( set ){
// We can't allow the type property to be changed (since it causes problems in IE)
- if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
+ if ( name == "type" && elem.nodeName.match(/(button|input)/i) && elem.parentNode )
throw "type property can't be changed";
elem[ name ] = value;
diff --git a/test/index.html b/test/index.html
index 4c47d92a5..97d9d60b5 100644
--- a/test/index.html
+++ b/test/index.html
@@ -70,7 +70,7 @@
<input type="text" id="name" name="name" value="name" />
<input type="search" id="search" name="search" value="search" />
- <button id="button" name="button">Button</button>
+ <button id="button" name="button" type="button">Button</button>
<textarea id="area1" maxlength="30">foobar</textarea>
diff --git a/test/unit/core.js b/test/unit/core.js
index a4e82eb6e..289a8bace 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -463,7 +463,7 @@ test("attr(Hash)", function() {
});
test("attr(String, Object)", function() {
- expect(19);
+ expect(21);
var div = jQuery("div").attr("foo", "bar"),
fail = false;
for ( var i = 0; i < div.size(); i++ ) {
@@ -537,6 +537,16 @@ test("attr(String, Object)", function() {
}
ok( thrown, "Exception thrown when trying to change type property" );
equals( "checkbox", check.attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
+
+ var button = jQuery("#button");
+ var thrown = false;
+ try {
+ button.attr('type','submit');
+ } catch(e) {
+ thrown = true;
+ }
+ ok( thrown, "Exception thrown when trying to change type property" );
+ equals( "button", button.attr('type'), "Verify that you can't change the type of a button element" );
});
if ( !isLocal ) {