how i can make the ".each" to starts with the div id small number "1" to the big number "5" ... 1 / 2 / 3 / 4 / 5
lets say i have this divs
<div class="TID_5">TID 5</div>
<div class="TID_4">TID 4</div>
<div class="TID_3">TID 3</div>
<div class="TID_2">TID 2</div>
<div class="TID_1">TID 1</div>
i have this jquery what im using, but starts with the first div class id number "5" but i need to start with number 1 ...
$("div[class*='TID_']").each(function() {
// code is come here ...
});
Try
$("div[class*='TID_']").sort(function(e1, e2){
return $(e1).attr('class') > $(e2).attr('class')
}).each(function() {
console.log($(this).text())
});
Demo: Fiddle
You can use index to reverse the elements.
Live Demo
elements = $("div[class*='TID_']")
elements.each(function(index) {
current = elements.eq(elements.length - index -1);
});
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