Skip to content

Commit

Permalink
Fixed #1070 by converting all setAttribute() values to a string which…
Browse files Browse the repository at this point in the history
… is what all browsers but IE did. This will bring IE in line with the others and fix the bug.
  • Loading branch information
davids549 committed Nov 28, 2007
1 parent 3ae5fbc commit ed7608d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core.js
Expand Up @@ -1042,7 +1042,8 @@ jQuery.extend({
if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode ) if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
throw "type property can't be changed"; 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 ) ) if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
Expand Down
10 changes: 9 additions & 1 deletion test/unit/core.js
Expand Up @@ -276,7 +276,7 @@ test("attr(Hash)", function() {
}); });


test("attr(String, Object)", function() { test("attr(String, Object)", function() {
expect(13); expect(16);
var div = $("div"); var div = $("div");
div.attr("foo", "bar"); div.attr("foo", "bar");
var pass = true; var pass = true;
Expand All @@ -302,6 +302,14 @@ test("attr(String, Object)", function() {
$("#name").attr('maxLength', '10'); $("#name").attr('maxLength', '10');
ok( document.getElementById('name').maxLength == '10', 'Set maxlength attribute' ); 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(); reset();


var type = $("#check2").attr('type'); var type = $("#check2").attr('type');
Expand Down

0 comments on commit ed7608d

Please sign in to comment.