I'm trying to get multiple attributes from unordered lists from multiple divs that look like this:
<div class="graph" style="display:none;">
<ul g-max='10'>
<li g-color='green' g-val='4'></li>
<li g-color='blue' g-val='3.6'></li>
<li g-color='red' g-val='8'></li>
</ul>
</div>
<div class="graph" style="display:none;">
<ul g-max='14'>
<li g-color='green' g-val='2'></li>
<li g-color='blue' g-val='9'></li>
<li g-color='red' g-val='3.98'></li>
</ul>
</div>
I'm trying to do this with jQuery and I'm using the following:
var graph_array = [];
$('.graph').each(function(divind)
{
$('ul').each(function(ulind)
{
$('li').each(function(liind)
{
graph_array[divind][ulind][liind]['g-val'] = $(this).attr('g-val');
graph_array[divind][ulind][liind]['g-color'] = $(this).attr('g-color');
});
});
});
alert(graph_array);
But, even when I move things around and try different techniques like .map() or .toArray(), nothing works. Any ideas? Thanks in advance!
EDIT: I'm wanting to have an ending result that'll look like this:
[{
{
{g-color:green, g-val:4},{g-color:blue, g-val:3.6},{g-color:red, g-val:8}
},
{
{g-color:green, g-val:2},{g-color:blue, g-val:9},{g-color:red, g-val:3.98}
}
}]
$('li').each, it's going to loop through everylion the page -- not just the ones that are inside theulthat the parent loop is referencing. Perhaps you want something like$(li, ulind).each, which would constrain the selector to the given context. (And you would need to do this at each level, of course.)[ {green:4, blue:3.6, red:8}, {green:2, blue:9, red:3.98} ];, or similar. This is legal js, and contains all the data available.