caesar
caesar

Reputation: 129

Get the text of all select element options?

Hi guys i have such select element:

<select name='files'>
<option value='1'>logo.jpg</option>
<option value='2'>file.ex</option>
</select>

i would like to have an array of the items like this:

files=logo.jpg,file.ex (i want the text not the values!)

thank you.

Upvotes: 0

Views: 31

Answers (1)

nnnnnn
nnnnnn

Reputation: 150010

var files = $('select[name="files"]').find("option").map(function() {
  return $(this).text();
}).get();

Further reading:

Upvotes: 2

Related Questions