Skip to content

Commit

Permalink
Fixed an issue with parentNode being accessed in attr() on disconnect…
Browse files Browse the repository at this point in the history
…ed DOM elements.
  • Loading branch information
jeresig committed Jan 12, 2009
1 parent af1b999 commit 0c97178
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core.js
Expand Up @@ -961,7 +961,7 @@ jQuery.extend({


// Safari mis-reports the default selected property of a hidden option // Safari mis-reports the default selected property of a hidden option
// Accessing the parent's selectedIndex property fixes it // Accessing the parent's selectedIndex property fixes it
if ( name == "selected" ) if ( name == "selected" && elem.parentNode )
elem.parentNode.selectedIndex; elem.parentNode.selectedIndex;


// If applicable, access the attribute via the DOM 0 way // If applicable, access the attribute via the DOM 0 way
Expand Down
4 changes: 3 additions & 1 deletion test/unit/core.js
Expand Up @@ -383,7 +383,7 @@ test("index(Object)", function() {
}); });


test("attr(String)", function() { test("attr(String)", function() {
expect(26); expect(27);
equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' ); equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' ); equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' ); equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
Expand All @@ -407,6 +407,8 @@ test("attr(String)", function() {
jQuery('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path jQuery('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' ); equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' );


equals( jQuery("<option/>").attr("selected"), false, "Check selected attribute on disconnected element." );



// Related to [5574] and [5683] // Related to [5574] and [5683]
var body = document.body, $body = jQuery(body); var body = document.body, $body = jQuery(body);
Expand Down

0 comments on commit 0c97178

Please sign in to comment.