From: David Serduke Date: Wed, 28 Nov 2007 23:13:59 +0000 (+0000) Subject: Fixed #1070 by converting all setAttribute() values to a string which is what all... X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=ed7608d8eedc0cd9082b5246581c0fc4ccb392db;p=jquery.git Fixed #1070 by converting all setAttribute() values to a string which is what all browsers but IE did. This will bring IE in line with the others and fix the bug. --- diff --git a/src/core.js b/src/core.js index 0ebc61d..39aa65b 100644 --- a/src/core.js +++ b/src/core.js @@ -1042,7 +1042,8 @@ jQuery.extend({ if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode ) throw "type property can't be changed"; - elem.setAttribute( name, value ); + // convert the value to a string (all browsers do this but IE) see #1070 + elem.setAttribute( name, "" + value ); } if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) ) diff --git a/test/unit/core.js b/test/unit/core.js index e71de2d..f77d1f8 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -276,7 +276,7 @@ test("attr(Hash)", function() { }); test("attr(String, Object)", function() { - expect(13); + expect(16); var div = $("div"); div.attr("foo", "bar"); var pass = true; @@ -302,6 +302,14 @@ test("attr(String, Object)", function() { $("#name").attr('maxLength', '10'); ok( document.getElementById('name').maxLength == '10', 'Set maxlength attribute' ); + // for #1070 + $("#name").attr('someAttr', '0'); + equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' ); + $("#name").attr('someAttr', 0); + equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' ); + $("#name").attr('someAttr', 1); + equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' ); + reset(); var type = $("#check2").attr('type');