TypeError: abc.getAttribute is not a function

What have I done wrong?

You treated a jQuery object like a DOM element. jQuery objects don't have a getAttribute method. You can either use .attr or .data instead.


abc is a jQuery object, so it doesn't have a getAttribute() function. it has an attr() function.


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);