Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery `.attr()` is not a function

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

like image 899
Marco Dinatsoli Avatar asked Sep 07 '26 04:09

Marco Dinatsoli


1 Answers

Conver oneOption to jQuery Object, like so

 $("option").each(function (index, oneOption) {
      options.push($(oneOption).attr("value"))
 });

Example

like image 177
Oleksandr T. Avatar answered Sep 10 '26 03:09

Oleksandr T.