Braxton C Braxton C - 3 months ago 12
HTML Question

calling .name on checkbox in array returns undefined

This is my function to add markers via google maps i want the title of the pin to be the name prop on the checkboxArray item and I can only seem to get undefined when i try .name i would love some feedback.

function addMarker() {
console.log(checkboxArray[iterator].name)
markers.push(new google.maps.Marker({
position: things[iterator],
map: map,
title: checkboxArray[iterator].name,
draggable: false,
animation: google.maps.Animation.DROP
}));
iterator++;
}


when i
console.log(checkboxArray[iterator].name)
i get
undefined

when i
console.log(checkboxArray[iterator])
i get
<option value="40.7002593,-111.7941413" name="French Fry" selected="" class="in">French Fry</option>

any ideas?

Answer

Use getAttribute()

checkboxArray[iterator].getAttribute("name");

JSFIDDLE