I have this code in html,
<ul id="locationSelect" style="visibility: visible;">
<li class="location-select" data-num="9"></li>
<li class="location-select" data-num="9"></li>
<li class="location-select" data-num="7"></li>
<li class="location-select" data-num="6"></li>
</ul>
Now I want to get the value of data-num
attribute when the user click on any <li>
element using pure javascript.
Here the code for javascript so far.
let locSel = document.getElementById('locationSelect').getElementsByClassName('location-select');
for(var i=0; i < locSel.length; i++) {
locSel[i].onclick = function() {
let markerNum = locSel[i].dataset.num;
google.maps.event.trigger(markers[markerNum], 'click');
};
}
Given that code, I got undefined, on the part of locSel[i]
and then got stack (I dont know the right spelling for this word stack). I have know idea.
any suggestion please?