File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -266,7 +266,9 @@ forEach({
266
266
} else if ( element . getAttribute ) {
267
267
// the extra argument "2" is to get the right thing for a.href in IE, see jQuery code
268
268
// some elements (e.g. Document) don't have get attribute, so return undefined
269
- return element . getAttribute ( name , 2 ) ;
269
+ var ret = element . getAttribute ( name , 2 ) ;
270
+ // normalize non-existing attributes to undefined (as jQuery)
271
+ return ret === null ? undefined : ret ;
270
272
}
271
273
} ,
272
274
Original file line number Diff line number Diff line change @@ -162,6 +162,10 @@ describe('jqLite', function(){
162
162
expect ( select . attr ( 'multiple' ) ) . toEqual ( true ) ;
163
163
} ) ;
164
164
165
+ it ( 'should return undefined for non-existing attributes' , function ( ) {
166
+ var elm = jqLite ( '<div class="any">a</div>' ) ;
167
+ expect ( elm . attr ( 'non-existing' ) ) . toBeUndefined ( ) ;
168
+ } ) ;
165
169
} ) ;
166
170
167
171
You can’t perform that action at this time.
0 commit comments