3๐
โ
I think youโve made it much more complicated than need be. Just select the td.goal
elements, and use .map()
to return an object to a new array with the values from the current goal.
var result = $("table.card tr[class^=section] td.goal").map(function(i, tr) {
var goal = $(this);
return {
value: parseInt(goal.text(), 10),
color:goal.prev().css('color') || '#000000'
};
}).toArray();
1๐
Use .map()
var data = $('.card tr').map(function () {
$this = $(this);
return {
value: $this.find('.goal').text(),
color: $this.find('.label').css('color') //will return like "rgb(194, 101, 88)"
}
}).get();
console.log(data);
Source:stackexchange.com