Suppose I have HTML elements like below
<span class="active" data-id="3"> Test 3 </span>
<span class="active" data-id="1"> Test 1 </span>
<span class="active" data-id="2"> Test 2 </span>
$(".active"].each(function(index,item){
var val = $(item).data("id");
console.log(val);
});
This will output
3
1
2
Is there anyway we can sort this loop based on data attribute and get the elements by the order or Data attribute or some other way so it will output
1
2
3
Thank you.