This always returns null for some reason?
alert($(element).val("option :first-child").val());
It will vary slightly depending on what the element
variable actually is, but:
If element
is a native DOM element:
alert($(element).find("option:first-child").val());
Or if element
is a jQuery-wrapped element already you can simplify to:
alert(element.find("option:first-child").val());
There were two bugs in what you were trying:
val
in place of find
to find the option
within the select
option
and :first-child
, which means "find a first-child which is a descendant of an option element"If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With