@@ -123,7 +123,7 @@ test( "attr(String)", function() {
123
123
optgroup . appendChild ( option ) ;
124
124
select . appendChild ( optgroup ) ;
125
125
126
- equal ( jQuery ( option ) . attr ( "selected" ) , "selected" , "Make sure that a single option is selected, even when in an optgroup." ) ;
126
+ equal ( jQuery ( option ) . prop ( "selected" ) , true , "Make sure that a single option is selected, even when in an optgroup." ) ;
127
127
128
128
var $img = jQuery ( "<img style='display:none' width='215' height='53' src='data/1x1.jpg'/>" ) . appendTo ( "body" ) ;
129
129
equal ( $img . attr ( "width" ) , "215" , "Retrieve width attribute an an element with display:none." ) ;
@@ -247,13 +247,14 @@ test( "attr(Hash)", function() {
247
247
} ) ;
248
248
249
249
test ( "attr(String, Object)" , function ( ) {
250
- expect ( 79 ) ;
250
+ expect ( 67 ) ;
251
251
252
252
var div = jQuery ( "div" ) . attr ( "foo" , "bar" ) ,
253
+ i = 0 ,
253
254
fail = false ;
254
255
255
- for ( var i = 0 ; i < div . size ( ) ; i ++ ) {
256
- if ( div . get ( i ) . getAttribute ( "foo" ) != "bar" ) {
256
+ for ( ; i < div . length ; i ++ ) {
257
+ if ( div [ i ] . getAttribute ( "foo" ) != = "bar" ) {
257
258
fail = i ;
258
259
break ;
259
260
}
@@ -272,73 +273,63 @@ test( "attr(String, Object)", function() {
272
273
equal ( jQuery ( "#name" ) . attr ( "name" ) , "something" , "Set name attribute" ) ;
273
274
jQuery ( "#name" ) . attr ( "name" , null ) ;
274
275
equal ( jQuery ( "#name" ) . attr ( "name" ) , undefined , "Remove name attribute" ) ;
276
+
275
277
var $input = jQuery ( "<input>" , {
276
278
name : "something" ,
277
279
id : "specified"
278
280
} ) ;
279
281
equal ( $input . attr ( "name" ) , "something" , "Check element creation gets/sets the name attribute." ) ;
280
282
equal ( $input . attr ( "id" ) , "specified" , "Check element creation gets/sets the id attribute." ) ;
281
283
282
- jQuery ( "#check2" ) . prop ( "checked" , true ) . prop ( "checked" , false ) . attr ( "checked" , true ) ;
283
- equal ( document . getElementById ( "check2" ) . checked , true , "Set checked attribute" ) ;
284
- equal ( jQuery ( "#check2" ) . prop ( "checked" ) , true , "Set checked attribute" ) ;
285
- equal ( jQuery ( "#check2" ) . attr ( "checked" ) , "checked" , "Set checked attribute" ) ;
286
- jQuery ( "#check2" ) . attr ( "checked" , false ) ;
287
- equal ( document . getElementById ( "check2" ) . checked , false , "Set checked attribute" ) ;
288
- equal ( jQuery ( "#check2" ) . prop ( "checked" ) , false , "Set checked attribute" ) ;
289
- equal ( jQuery ( "#check2" ) . attr ( "checked" ) , undefined , "Set checked attribute" ) ;
290
- jQuery ( "#text1" ) . attr ( "readonly" , true ) ;
291
- equal ( document . getElementById ( "text1" ) . readOnly , true , "Set readonly attribute" ) ;
292
- equal ( jQuery ( "#text1" ) . prop ( "readOnly" ) , true , "Set readonly attribute" ) ;
293
- equal ( jQuery ( "#text1" ) . attr ( "readonly" ) , "readonly" , "Set readonly attribute" ) ;
294
- jQuery ( "#text1" ) . attr ( "readonly" , false ) ;
295
- equal ( document . getElementById ( "text1" ) . readOnly , false , "Set readonly attribute" ) ;
296
- equal ( jQuery ( "#text1" ) . prop ( "readOnly" ) , false , "Set readonly attribute" ) ;
297
- equal ( jQuery ( "#text1" ) . attr ( "readonly" ) , undefined , "Set readonly attribute" ) ;
298
-
299
- jQuery ( "#check2" ) . prop ( "checked" , true ) ;
300
- equal ( document . getElementById ( "check2" ) . checked , true , "Set checked attribute" ) ;
301
- equal ( jQuery ( "#check2" ) . prop ( "checked" ) , true , "Set checked attribute" ) ;
302
- equal ( jQuery ( "#check2" ) . attr ( "checked" ) , "checked" , "Set checked attribute" ) ;
303
- jQuery ( "#check2" ) . prop ( "checked" , false ) ;
304
- equal ( document . getElementById ( "check2" ) . checked , false , "Set checked attribute" ) ;
305
- equal ( jQuery ( "#check2" ) . prop ( "checked" ) , false , "Set checked attribute" ) ;
306
- equal ( jQuery ( "#check2" ) . attr ( "checked" ) , undefined , "Set checked attribute" ) ;
307
-
308
- jQuery ( "#check2" ) . attr ( "checked" , "checked" ) ;
309
- equal ( document . getElementById ( "check2" ) . checked , true , "Set checked attribute with 'checked'" ) ;
310
- equal ( jQuery ( "#check2" ) . prop ( "checked" ) , true , "Set checked attribute" ) ;
311
- equal ( jQuery ( "#check2" ) . attr ( "checked" ) , "checked" , "Set checked attribute" ) ;
312
-
313
- QUnit . reset ( ) ;
284
+ // As of fixing #11115, we make no promises about the effect of .attr on boolean properties
285
+ $input = jQuery ( "#check2" ) ;
286
+ $input . prop ( "checked" , true ) . prop ( "checked" , false ) . attr ( "checked" , true ) ;
287
+ equal ( $input . attr ( "checked" ) , "checked" , "Set checked (verified by .attr)" ) ;
288
+ $input . prop ( "checked" , false ) . prop ( "checked" , true ) . attr ( "checked" , false ) ;
289
+ equal ( $input . attr ( "checked" ) , undefined , "Remove checked (verified by .attr)" ) ;
290
+
291
+ $input = jQuery ( "#text1" ) . prop ( "readOnly" , true ) . prop ( "readOnly" , false ) . attr ( "readonly" , true ) ;
292
+ equal ( $input . attr ( "readonly" ) , "readonly" , "Set readonly (verified by .attr)" ) ;
293
+ $input . prop ( "readOnly" , false ) . prop ( "readOnly" , true ) . attr ( "readonly" , false ) ;
294
+ equal ( $input . attr ( "readonly" ) , undefined , "Remove readonly (verified by .attr)" ) ;
295
+
296
+ $input = jQuery ( "#check2" ) . attr ( "checked" , true ) . attr ( "checked" , false ) . prop ( "checked" , true ) ;
297
+ equal ( $input [ 0 ] . checked , true , "Set checked property (verified by native property)" ) ;
298
+ equal ( $input . prop ( "checked" ) , true , "Set checked property (verified by .prop)" ) ;
299
+ equal ( $input . attr ( "checked" ) , undefined , "Setting checked property doesn't affect checked attribute" ) ;
300
+ $input . attr ( "checked" , false ) . attr ( "checked" , true ) . prop ( "checked" , false ) ;
301
+ equal ( $input [ 0 ] . checked , false , "Clear checked property (verified by native property)" ) ;
302
+ equal ( $input . prop ( "checked" ) , false , "Clear checked property (verified by .prop)" ) ;
303
+ equal ( $input . attr ( "checked" ) , "checked" , "Clearing checked property doesn't affect checked attribute" ) ;
304
+
305
+ $input = jQuery ( "#check2" ) . attr ( "checked" , false ) . attr ( "checked" , "checked" ) ;
306
+ equal ( $input . attr ( "checked" ) , "checked" , "Set checked to 'checked' (verified by .attr)" ) ;
314
307
315
308
var $radios = jQuery ( "#checkedtest" ) . find ( "input[type='radio']" ) ;
316
309
$radios . eq ( 1 ) . click ( ) ;
317
310
equal ( $radios . eq ( 1 ) . prop ( "checked" ) , true , "Second radio was checked when clicked" ) ;
318
- equal ( $radios . attr ( "checked" ) , $radios [ 0 ] . checked ? "checked" : undefined , "Known booleans do not fall back to attribute presence (#10278)" ) ;
319
-
320
- jQuery ( "#text1" ) . prop ( "readOnly" , true ) ;
321
- equal ( document . getElementById ( "text1" ) . readOnly , true , "Set readonly attribute" ) ;
322
- equal ( jQuery ( "#text1" ) . prop ( "readOnly" ) , true , "Set readonly attribute" ) ;
323
- equal ( jQuery ( "#text1" ) . attr ( "readonly" ) , "readonly" , "Set readonly attribute" ) ;
324
- jQuery ( "#text1" ) . prop ( "readOnly" , false ) ;
325
- equal ( document . getElementById ( "text1" ) . readOnly , false , "Set readonly attribute" ) ;
326
- equal ( jQuery ( "#text1" ) . prop ( "readOnly" ) , false , "Set readonly attribute" ) ;
327
- equal ( jQuery ( "#text1" ) . attr ( "readonly" ) , undefined , "Set readonly attribute" ) ;
328
-
329
- jQuery ( "#name" ) . attr ( "maxlength" , "5" ) ;
330
- equal ( document . getElementById ( "name" ) . maxLength , 5 , "Set maxlength attribute" ) ;
331
- jQuery ( "#name" ) . attr ( "maxLength" , "10" ) ;
332
- equal ( document . getElementById ( "name" ) . maxLength , 10 , "Set maxlength attribute" ) ;
311
+ equal ( $radios . eq ( 0 ) . attr ( "checked" ) , "checked" , "First radio is still [checked]" ) ;
312
+
313
+ $input = jQuery ( "#text1" ) . attr ( "readonly" , false ) . prop ( "readOnly" , true ) ;
314
+ equal ( $input [ 0 ] . readOnly , true , "Set readonly property (verified by native property)" ) ;
315
+ equal ( $input . prop ( "readOnly" ) , true , "Set readonly property (verified by .prop)" ) ;
316
+ $input . attr ( "readonly" , true ) . prop ( "readOnly" , false ) ;
317
+ equal ( $input [ 0 ] . readOnly , false , "Clear readonly property (verified by native property)" ) ;
318
+ equal ( $input . prop ( "readOnly" ) , false , "Clear readonly property (verified by .prop)" ) ;
319
+
320
+ $input = jQuery ( "#name" ) . attr ( "maxlength" , "5" ) ;
321
+ equal ( $input [ 0 ] . maxLength , 5 , "Set maxlength (verified by native property)" ) ;
322
+ $input . attr ( "maxLength" , "10" ) ;
323
+ equal ( $input [ 0 ] . maxLength , 10 , "Set maxlength (verified by native property)" ) ;
333
324
334
325
// HTML5 boolean attributes
335
326
var $text = jQuery ( "#text1" ) . attr ( {
336
327
"autofocus" : true ,
337
328
"required" : true
338
329
} ) ;
339
- equal ( $text . attr ( "autofocus" ) , "autofocus" , "Set boolean attributes to the same name " ) ;
340
- equal ( $text . attr ( "autofocus" , false ) . attr ( "autofocus" ) , undefined , "Setting autofocus attribute to false removes it" ) ;
341
- equal ( $text . attr ( "required" ) , "required" , "Set boolean attributes to the same name " ) ;
330
+ equal ( $text . attr ( "autofocus" ) , "autofocus" , "Reading autofocus attribute yields 'autofocus' " ) ;
331
+ equal ( $text . attr ( "autofocus" , false ) . attr ( "autofocus" ) , undefined , "Setting autofocus to false removes it" ) ;
332
+ equal ( $text . attr ( "required" ) , "required" , "Reading required attribute yields 'required' " ) ;
342
333
equal ( $text . attr ( "required" , false ) . attr ( "required" ) , undefined , "Setting required attribute to false removes it" ) ;
343
334
344
335
var $details = jQuery ( "<details open></details>" ) . appendTo ( "#qunit-fixture" ) ;
@@ -368,13 +359,14 @@ test( "attr(String, Object)", function() {
368
359
strictEqual ( $elem . attr ( "nonexisting" ) , undefined , "attr(name, value) works correctly on comment and text nodes (bug #7500)." ) ;
369
360
} ) ;
370
361
362
+ // Register the property name to avoid generating a new global when testing window
363
+ Globals . register ( "nonexisting" ) ;
371
364
jQuery . each ( [ window , document , obj , "#firstp" ] , function ( i , elem ) {
372
- // use iframeCallback to avoid generating a new global when testing window
373
- var oldVal = elem . iframeCallback ,
365
+ var oldVal = elem . nonexisting ,
374
366
$elem = jQuery ( elem ) ;
375
367
strictEqual ( $elem . attr ( "nonexisting" ) , undefined , "attr works correctly for non existing attributes (bug #7500)." ) ;
376
- equal ( $elem . attr ( "iframeCallback " , "foo" ) . attr ( "iframeCallback " ) , "foo" , "attr falls back to prop on unsupported arguments" ) ;
377
- elem . iframeCallback = oldVal ;
368
+ equal ( $elem . attr ( "nonexisting " , "foo" ) . attr ( "nonexisting " ) , "foo" , "attr falls back to prop on unsupported arguments" ) ;
369
+ elem . nonexisting = oldVal ;
378
370
} ) ;
379
371
380
372
var table = jQuery ( "#table" ) . append ( "<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>" ) ,
0 commit comments