If .attr() is run on no elements undefined should be returned (as should be the case when no attribute is found). Fixes #6012.

This commit is contained in:
jeresig 2010-02-13 02:23:38 -05:00
parent 83a044f1b5
commit abcc1a76ee
2 changed files with 5 additions and 2 deletions

View file

@ -799,7 +799,7 @@ function access( elems, key, value, exec, fn, pass ) {
} }
// Getting an attribute // Getting an attribute
return length ? fn( elems[0], key ) : null; return length ? fn( elems[0], key ) : undefined;
} }
function now() { function now() {

View file

@ -4,7 +4,7 @@ var bareObj = function(value) { return value; };
var functionReturningObj = function(value) { return (function() { return value; }); }; var functionReturningObj = function(value) { return (function() { return value; }); };
test("attr(String)", function() { test("attr(String)", function() {
expect(28); expect(30);
// This one sometimes fails randomly ?! // This one sometimes fails randomly ?!
equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' ); equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
@ -61,6 +61,9 @@ test("attr(String)", function() {
select.appendChild( optgroup ); select.appendChild( optgroup );
equals( jQuery(option).attr("selected"), true, "Make sure that a single option is selected, even when in an 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 ) { if ( !isLocal ) {