Reputation: 91
I'm trying to get the innerHTML/Text from the select options from a dropdownlist instead of the value.
var Array = []; $('#select option').each(function(){Array.push(this.value)});
The method above works, but it only stores the value attribute of the options.
For example, if my option were to be <option value="John">Hello</option>
, It would store John
instead of Hello
. I want it to store whatever's in the innerHTML of the option. How do I go about doing this? .innerHTML()
before the .each()
doesn't work.
Upvotes: 0
Views: 35
Reputation: 97672
.innerHTML
inside the each
var Array = [];
$('#select option').each(function(){
Array.push(this.innerHTML);
});
Upvotes: 4