I know how to get the attributes of an element, using jquery. But I’m not sure how to do it with the actual options in a select field.
<select referenceID="55" name="test" id="test">
<option value="1">first option</option>
<option value="2">second option</option>
<option value="3">third option</option>
</select>
To get the referenceID I would just do this:
$("#test").attr("referenceID");
And when I want to get the value:
$("#test").val();
But I want to get a little more interesting. I want to put some specific info into each option:
<select name="test" id="test">
<option value="1" title="something here"*>first option</option>
<option value="2" title="something else here">second option</option>
<option value="3" title="another thing here">third option</option>
</select>
Is it possible to grab an attribute within the options tags?
I intend to have an onselect function that reads the title tag, and does helps me with some other things.
Presuming you want to find the
titleattribute of the selected option…That is, find the descendant element of
#testthat is (a) an option element and (b) is selected.If you already have a selection containing
#test, you can do this withfind: