I am trying to get values of specific option tags using jQuery.
This is my HTML:
<select name="modele" class="wyszselect" onchange="przenies(this[this.selectedIndex].value);">
<option value="0">Choose model</option>
<option value="242">242</option>
<option value="243">243</option>
<option value="244">244</option>
<option value="246">246</option>
<option value="320">320</option>
<option value="324">324</option>
<option value="328">328</option>
<option value="33">33</option>
</select>
This is my jQuery code:
$(document).ready(function () {
var options = [];
$("option").each(function (index, oneOption) {
options.push(oneOption.attr("value"))
});
console.log(options);
});
I got this error:
Uncaught TypeError: oneOption.attr is not a function
Conver oneOption to jQuery Object, like so
$("option").each(function (index, oneOption) {
options.push($(oneOption).attr("value"))
});
Example
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