For the following code:
<span class="map-marker" data-lng="101.7113506794"></span>
<span class="map-marker" data-lng="101.6311097146"></span>
var abc = $('.map-marker:first');
var xyz = abc.getAttribute("data-lat");
console.log(xyz);
I get the error message: TypeError: abc.getAttribute is not a function
. What have I done wrong?
Try this may be:
var abc = $(".map-marker:first")[0];
var xyz = abc.getAttribute("data-lat");
console.log(xyz);
Or this:
var abc = $(".map-marker:first");
var xyz = abc.data("lat");
console.log(xyz);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With