Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery val() returns an array with IE8 on select/option element

The following alert returns "string" in the majors browsers. Returns "object" (an array of one element) on <=IE8.

HTML:

<SELECT id="adults_1" type="select">
    <OPTION value="1">1 persona</OPTION>
</SELECT>​

JS:

 alert(typeof $("#adults_1").val()); 

JsFiddle: http://jsfiddle.net/JM9AY/2/

Is it a bug or it is the expected value? If it's a bug, is there a workaround?

like image 372
Jordi P.S. Avatar asked Nov 18 '25 20:11

Jordi P.S.


1 Answers

Removing type="select" corrects this unexpected behavior. What is the meaning of the type attribute here in any case? There is no such attribute in HTML5.

like image 66
Jon Avatar answered Nov 20 '25 10:11

Jon