Skip to content

Commit ff75767

Browse files
author
timmywil
committed
Minor adjustments and cleanup, including normalizing the value to a string when setting( list of changes below )
- Normalize set value to string to synchronize return type cross-browser - Add style attrHook to propHooks to support style getting in all browsers for both attr and prop - Extend the selected propHook instead of overriding a possible set function - Remove selected propHook TODO since there is no selected content attribute and it should return null
1 parent 8cbf551 commit ff75767

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/attributes.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ jQuery.extend({
313313
return ret;
314314

315315
} else {
316-
elem.setAttribute( name, value );
316+
elem.setAttribute( name, "" + value );
317317
return value;
318318
}
319319

@@ -440,10 +440,8 @@ if ( !jQuery.support.getSetAttribute ) {
440440
var ret = elem.getAttributeNode( name );
441441
if ( ret ) {
442442
ret.nodeValue = value;
443-
} else {
444-
elem.setAttribute( name, value );
443+
return value;
445444
}
446-
return value;
447445
}
448446
};
449447
}
@@ -458,9 +456,6 @@ jQuery.each([ "selected", "checked", "readonly", "disabled" ], function( i, name
458456
jQuery.removeAttr( elem, name );
459457
return false;
460458
}
461-
462-
elem.setAttribute( name, value );
463-
return value;
464459
}
465460
});
466461
});
@@ -477,7 +472,7 @@ if ( !jQuery.support.hrefNormalized ) {
477472
}
478473

479474
if ( !jQuery.support.style ) {
480-
jQuery.attrHooks.style = {
475+
jQuery.propHooks.style = jQuery.attrHooks.style = {
481476
get: function( elem ) {
482477
return elem.style.cssText;
483478
},
@@ -490,24 +485,20 @@ if ( !jQuery.support.style ) {
490485
// Safari mis-reports the default selected property of an option
491486
// Accessing the parent's selectedIndex property fixes it
492487
if ( !jQuery.support.optSelected ) {
493-
494-
jQuery.propHooks.selected = {
488+
jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, {
495489
get: function( elem ) {
496490
var parent = elem.parentNode;
497-
491+
498492
if ( parent ) {
499493
parent.selectedIndex;
500-
501-
// TODO: We may need an attrHook for selected that simply defers to prop?
502-
// The attr is undefined if the option is created with createElement and not on the DOM
503-
494+
504495
// Make sure that it also works with optgroups, see #5701
505496
if ( parent.parentNode ) {
506497
parent.parentNode.selectedIndex;
507498
}
508499
}
509500
}
510-
};
501+
});
511502
}
512503

513504
})( jQuery );

0 commit comments

Comments
 (0)