Say I have:
HTML:
<select id="mySelect"><option value="0">option-1</option>...</select>
JS:
var select = $("#mySelect");
and I further down, I want to do:
var val = $("#mySelect option:selected").val();
I’ve tried this, but it seems to only return the text, not the value attribute:
$(select + "option:selected").val();
$(select + "option:selected").attr("value"); // also doesn't work
Try the .find() method.
(just couldn’t use “select” since it’s reserved in so many languages)
This may be a little more efficient since you’re not doing a new find each time.