Rikard Rikard - 4 months ago 14
jQuery Question

Select options without value attr

Is this correct or invalid markup? (when the option has no value)

Is this the expected jQuery behaviour for

when there is no

<select id="select_ID">

If I use
I get "Name"/"Recent", but if the option had a value I would get the value's content.

I know there is
to get "Name" & "Recent" in this example. Just confused why does
gives me the
when there is no value assigned.

FIDDLE (notice the different result of the alerts)


This has nothing to do with jQuery, that's how the browser handles it.


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

Ref: http://www.w3.org/TR/html5/forms.html#attr-option-value