diff options
author | John Resig <jeresig@gmail.com> | 2009-01-12 14:00:35 +0000 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2009-01-12 14:00:35 +0000 |
commit | 0c97178553606c01b999441836e23f9f36c645a3 (patch) | |
tree | 4fbf771c8e4719314061a4cce111ea304e34cb4c | |
parent | af1b9994a41e04a377e42bbe756851f5fff61097 (diff) | |
download | jquery-0c97178553606c01b999441836e23f9f36c645a3.tar.gz jquery-0c97178553606c01b999441836e23f9f36c645a3.zip |
Fixed an issue with parentNode being accessed in attr() on disconnected DOM elements.
-rw-r--r-- | src/core.js | 2 | ||||
-rw-r--r-- | test/unit/core.js | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/core.js b/src/core.js index 78f0cae2d..6c439a5a6 100644 --- a/src/core.js +++ b/src/core.js @@ -961,7 +961,7 @@ jQuery.extend({ // Safari mis-reports the default selected property of a hidden option // Accessing the parent's selectedIndex property fixes it - if ( name == "selected" ) + if ( name == "selected" && elem.parentNode ) elem.parentNode.selectedIndex; // If applicable, access the attribute via the DOM 0 way diff --git a/test/unit/core.js b/test/unit/core.js index 4d04af759..8483361a1 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -383,7 +383,7 @@ test("index(Object)", function() { }); test("attr(String)", function() { - expect(26); + expect(27); 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('type'), "text", 'Check for type attribute' ); @@ -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 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] var body = document.body, $body = jQuery(body); |