Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make sure that selected works in Safari on options in optgroups. Fixe…

…s #5701.
  • Loading branch information...
commit 4729f4d44326fd302c63af8f3324b6c4bac54084 1 parent baff0b0
John Resig authored
11  src/attributes.js
@@ -261,12 +261,17 @@ jQuery.extend({
261 261
 		// Only do all the following if this is a node (faster for style)
262 262
 		if ( elem.nodeType === 1 ) {
263 263
 			// These attributes require special treatment
264  
-			var special = rspecialurl.test( name );
  264
+			var special = rspecialurl.test( name ), parent = elem.parentNode;
265 265
 
266 266
 			// Safari mis-reports the default selected property of a hidden option
267 267
 			// Accessing the parent's selectedIndex property fixes it
268  
-			if ( name === "selected" && elem.parentNode ) {
269  
-				elem.parentNode.selectedIndex;
  268
+			if ( name === "selected" && parent ) {
  269
+				parent.selectedIndex;
  270
+
  271
+				// Make sure that it also works with optgroups, see #5701
  272
+				if ( parent.parentNode ) {
  273
+					parent.parentNode.selectedIndex;
  274
+				}
270 275
 			}
271 276
 
272 277
 			// If applicable, access the attribute via the DOM 0 way
8  test/unit/attributes.js
@@ -4,7 +4,7 @@ var bareObj = function(value) { return value; };
4 4
 var functionReturningObj = function(value) { return (function() { return value; }); };
5 5
 
6 6
 test("attr(String)", function() {
7  
-	expect(27);
  7
+	expect(28);
8 8
 
9 9
 	// This one sometimes fails randomly ?!
10 10
 	equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
@@ -55,6 +55,12 @@ test("attr(String)", function() {
55 55
 	ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' );
56 56
 
57 57
 	body.removeAttribute('foo'); // Cleanup
  58
+
  59
+	var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option");
  60
+	optgroup.appendChild( option );
  61
+	select.appendChild( optgroup );
  62
+
  63
+	equals( jQuery(option).attr("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
58 64
 });
59 65
 
60 66
 if ( !isLocal ) {

0 notes on commit 4729f4d

Please sign in to comment.
Something went wrong with that request. Please try again.