I have some data provided from a file.txt wich are display like this :
<div class="nbvote">465</div>
<div class="nbvote">12</div>
<div class="nbvote">1862</div>
[...]
<div class="nbvote">3</div>
And i have in the same page multiple div (90) like this :
<div class="grid_4">
<div class="grid_4">
<div class="grid_4">
[...]
<div class="grid_4">
Now i want to add each data (465,12,1862,...,3) as class to each div class="grid_4" like this :
<div class="grid_4 465">
<div class="grid_4 12">
<div class="grid_4 1862">
[...]
<div class="grid_4 3">
How can i do that ? I was thinking using lenght, but i wasn't be able to do this.
By the way, the data are the number of vote and i would like to add them as class to each div grid_4 and then sort ascending.
Sorry for my english, not my first langage.
Ty
try this:
$('.nbvote').each(function(i, v){
var cls = $(this).text();
$('.grid_4:eq('+i+')').addClass(cls)
})
DEMO
note: class names Must begin with a letter A-Z or a-z
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With