I can’t run the jquerry loop

Asked

Viewed 38 times

1

I need to create a loop so I can feed it a graphic.

while($(".previsto").eq(0).text(),){}

I need to take these values eq(0), eq(1), eq(2)...

$(".previsto").eq(0).text(),
$(".previsto").eq(1).text(),
$(".previsto").eq(2).text(),

...

  • 'Cause there’s a comma after the .text()?

  • Because this is to generate the graph, so you need the comma, I want to create a loop so that it is dynamic. eq() is like an index

  • I’m trying something like :

  • for(var i = i; i < ($(".predicted").eq(0).text()).length; i++){ console.log($(".predicted").eq(0).text(); }

  • I stored the result of a Divs Query inside a loop in php, I need to take the values of these Divs, so the selector is a "." class. I need a loop to take the values of the div " $(".predicted"). eq(0). text();" using this eq function()

  • Try it this way: for(var i = 0; i < $(".previsto").length ; i++){ console.log($(".previsto").eq(i).text()); }

  • Our partner, it worked. Mt thank you

Show 2 more comments

1 answer

0


To get the element indices (from first to last), the loop variable must start at 0 up to the number of elements -1:

for(var i = 0; i < $(".previsto").length; i++){ 
    console.log($(".previsto").eq(i).text());
}

The $(".previsto").length returns the number of elements with the class .previsto, and the variable i must start 0 as long as it is less than $(".previsto").length.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.