Reputation: 769
i want count index of nodes like this:
var serise = [];
serise.push({
name: foo.eq(0).text(),
data: foo.eq(1).text(),
family: foo.eq(2).text(),
})
serise.push({
name: foo.eq(3).text(),
data: foo.eq(4).text(),
family: foo.eq(5).text(),
})
serise.push({
name: foo.eq(6).text(),
data: foo.eq(7).text(),
family: foo.eq(8).text(),
})
and slice every sequence of this nodes, for more info i have html file just with span and those spans without any class and id, i can find index of spans like above now just want slice every index sequence in 3.
Upvotes: 0
Views: 57
Reputation: 10724
Please have a look on this solution.
Sample HTML
<span>data1</span>
<span>family1</span>
<span>Name2</span>
<span>data2</span>
<span>family2</span>
<span>Name3</span>
<span>data3</span>
<span>family3</span>
JS Script
var serise = [];
var obj=$(document).find('span');// here I used 'document' in your case it might be diffrent
var spanCount=obj.length;
var tempObj={};
for (var i=0; i<spanCount;i++){
tempObj={};
tempObj.name =obj.eq(i).text();
tempObj.data =obj.eq(++i).text();
tempObj.family=obj.eq(++i).text();
serise.push(tempObj);
}
alert(JSON.stringify(serise));
I still don't know the exact requirement but I just hope the given solution above will help you to solve your problem.
Upvotes: 1