Skip to content

Commit

Permalink
Normalize css property names to lowercase for comparisons on a .attr(…
Browse files Browse the repository at this point in the history
…'style') call since IE uppercases everything
  • Loading branch information
timmywil committed Apr 3, 2011
1 parent ad2b3bc commit 6f79bee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/attributes.js
Expand Up @@ -477,7 +477,8 @@ if ( !jQuery.support.style ) {
jQuery.attrHooks.style = { jQuery.attrHooks.style = {
get: function( elem ) { get: function( elem ) {
// Return undefined in the case of empty string // Return undefined in the case of empty string
return elem.style.cssText || undefined; // Normalize to lowercase since IE uppercases css property names
return elem.style.cssText.toLowerCase() || undefined;
}, },
set: function( elem, value ) { set: function( elem, value ) {
return (elem.style.cssText = "" + value); return (elem.style.cssText = "" + value);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/attributes.js
Expand Up @@ -135,8 +135,8 @@ test("attr(String)", function() {
equals( $img.attr('height'), "53", "Retrieve height attribute an an element with display:none." ); equals( $img.attr('height'), "53", "Retrieve height attribute an an element with display:none." );


// Check for style support // Check for style support
ok( !!~jQuery('#dl').attr('style').indexOf('absolute'), 'Check style attribute getter' ); ok( !!~jQuery('#dl').attr('style').indexOf('position'), 'Check style attribute getter, also normalize css props to lowercase' );
ok( !!~jQuery('#foo').attr('style', 'position:absolute;').attr('style').indexOf('absolute'), 'Check style setter' ); ok( !!~jQuery('#foo').attr('style', 'position:absolute;').attr('style').indexOf('position'), 'Check style setter' );


ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); 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." ); ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
Expand Down

0 comments on commit 6f79bee

Please sign in to comment.