if ( this.length ) {
var elem = this[0];
+ if( jQuery.nodeName( elem, 'option' ) )
+ return (elem.attributes.value || {}).specified ? elem.value : elem.text;
+
// We need to handle select boxes special
if ( jQuery.nodeName( elem, "select" ) ) {
var index = elem.selectedIndex,
if ( option.selected ) {
// Get the specifc value for the option
- value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
+ value = jQuery(option).val();
// We don't need an array for one selects
if ( one )
});\r
\r
test("val()", function() {\r
- expect(3);\r
+ expect(8);\r
+\r
equals( jQuery("#text1").val(), "Test", "Check for value of input element" );\r
// ticket #1714 this caused a JS error in IE\r
equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );\r
ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );\r
+ \r
+ equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );\r
+\r
+ isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );\r
+\r
+ equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );\r
+ \r
+ equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );\r
+ \r
+ equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );\r
+ \r
});\r
\r
test("val(String/Number)", function() {\r
isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );\r
isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );\r
equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );\r
- isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");\r
+ isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')");\r
\r
var selects = jQuery("#form select");\r
isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");\r
t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] );
t( "Not", "a.blog:not(.link)", ["mark"] );
- t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d"] );
- t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d"] );
+ t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );
+ t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d", "option3e"] );
t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );
t( "nth Element", "p:nth(1)", ["ap"] );