Skip to content

Commit

Permalink
If .attr() is run on no elements undefined should be returned (as sho…
Browse files Browse the repository at this point in the history
…uld be the case when no attribute is found). Fixes #6012.
  • Loading branch information
jeresig committed Feb 13, 2010
1 parent 83a044f commit abcc1a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core.js
Expand Up @@ -799,7 +799,7 @@ function access( elems, key, value, exec, fn, pass ) {
}

// Getting an attribute
return length ? fn( elems[0], key ) : null;
return length ? fn( elems[0], key ) : undefined;
}

function now() {
Expand Down
5 changes: 4 additions & 1 deletion test/unit/attributes.js
Expand Up @@ -4,7 +4,7 @@ var bareObj = function(value) { return value; };
var functionReturningObj = function(value) { return (function() { return value; }); };

test("attr(String)", function() {
expect(28);
expect(30);

// This one sometimes fails randomly ?!
equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
Expand Down Expand Up @@ -61,6 +61,9 @@ test("attr(String)", function() {
select.appendChild( optgroup );

equals( jQuery(option).attr("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );

ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
});

if ( !isLocal ) {
Expand Down

0 comments on commit abcc1a7

Please sign in to comment.