Extract multiple data from DOM in jQuery?
There is a node like this
<img src=β"http:β/β/βx.JPG" data-latitude=β"0" data-longitude=β"0">β
In jQuery, I can extract two data attributes like this:
a=node.data("latitude")
b=node.data("longitude")
I was wondering if there is a way to extract multiple attributes data
in one go, for example:
latLng = node.data([latitude, longitude]) // not working
+3
source to share
3 answers
I was wondering if there is a way to extract multiple attribute data in one go, for example:
latLng = node.data([latitude, longitude]) // not working
Note. Not sure if the expected result is an array of values ββfrom .node.data()
?
var data = $.map($("img").data(), function(value) {
return value
});
console.log(data);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<img src=β"http:././.x.JPG" data-latitude="0" data-longitude="0">
+1
source to share