jquery - Select options without value attribute -


is correct or invalid markup (when option has no value)?
expected jquery behaviour .val() when there no value="" assigned?

<select id="select_id">     <option></option>     <option>name</option>     <option>recent</option> </select> 

if use $("#select_id").val(); "name"/"recent", if option had value, value's content.

i know there .text() "name" , "recent" in example. confused why .val() gives me .text() when there no value assigned.

fiddle (notice different result of alerts)

this has nothing jquery. that's how browser handles it.

http://jsfiddle.net/jdw8n/1/

$("#select_id").change(function () {     var val = $("#select_id option:selected")[0].value;     alert(val); // somevalue or recent }); 

reference: http://www.w3.org/tr/html5/forms.html#attr-option-value

the value attribute provides value element. value of option element value of value content attribute, if there one, or, if there not, value of element's text idl attribute.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -