aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2012-12-11 23:03:12 -0500
committerDave Methvin <dave.methvin@gmail.com>2012-12-11 23:16:08 -0500
commitaad235b3251494afe71fd5bb6031e11965af9bdb (patch)
tree0d44af1b0b2adb9de7e03633954811cf89859410
parent1d1c80d377bf3e4ae382a6ecd06624866e620fb6 (diff)
downloadjquery-aad235b3251494afe71fd5bb6031e11965af9bdb.tar.gz
jquery-aad235b3251494afe71fd5bb6031e11965af9bdb.zip
Fix #13011. Let 'type' attribute be set if the browser allows.
-rw-r--r--src/attributes.js9
-rw-r--r--test/unit/attributes.js14
2 files changed, 7 insertions, 16 deletions
diff --git a/src/attributes.js b/src/attributes.js
index ffba0b1c7..ffeab3c69 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -1,7 +1,6 @@
var nodeHook, boolHook, fixSpecified,
rclass = /[\t\r\n]/g,
rreturn = /\r/g,
- rtype = /^(?:input|button)$/i,
rfocusable = /^(?:input|select|textarea|button|object)$/i,
rclickable = /^(?:a|area)$/i,
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
@@ -366,13 +365,9 @@ jQuery.extend({
attrHooks: {
type: {
set: function( elem, value ) {
- // We can't allow the type property to be changed (since it causes problems in IE)
- if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
- jQuery.error( "type property can't be changed" );
- } else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
+ if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
// Setting the type on a radio button after the value resets the value in IE6-9
- // Reset value to it's default in case type is set after value
- // This is for element creation
+ // Reset value to default in case type is set after value during creation
var val = elem.value;
elem.setAttribute( "type", value );
if ( val ) {
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index d3dbd4f17..3144dc626 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -221,7 +221,7 @@ test( "attr(Hash)", function() {
});
test( "attr(String, Object)", function() {
- expect( 81 );
+ expect( 79 );
var div = jQuery("div").attr("foo", "bar"),
fail = false;
@@ -379,14 +379,12 @@ test( "attr(String, Object)", function() {
// Type
var type = jQuery("#check2").attr("type");
- var thrown = false;
try {
jQuery("#check2").attr( "type", "hidden" );
+ ok( true, "No exception thrown on input type change" );
} catch( e ) {
- thrown = true;
+ ok( true, "Exception thrown on input type change: " + e );
}
- ok( thrown, "Exception thrown when trying to change type property" );
- equal( type, jQuery("#check2").attr("type"), "Verify that you can't change the type of an input element" );
var check = document.createElement("input");
thrown = true;
@@ -409,14 +407,12 @@ test( "attr(String, Object)", function() {
equal( "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");
- thrown = false;
try {
button.attr( "type", "submit" );
+ ok( true, "No exception thrown on button type change" );
} catch( e ) {
- thrown = true;
+ ok( true, "Exception thrown on button type change: " + e );
}
- ok( thrown, "Exception thrown when trying to change type property" );
- equal( "button", button.attr("type"), "Verify that you can't change the type of a button element" );
var $radio = jQuery( "<input>", {
"value": "sup",