admin管理员组文章数量:1314442
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 e here ...
});
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 e here ...
});
Share
Improve this question
edited Jul 30, 2013 at 13:04
Kris Harper
5,8729 gold badges54 silver badges99 bronze badges
asked Jul 30, 2013 at 9:01
Mihai ViteazuMihai Viteazu
1,6613 gold badges13 silver badges16 bronze badges
4
-
if jquery return an array then this will work
$("div[class*='TID_']").reverse()
– bugwheels94 Commented Jul 30, 2013 at 9:03 - @Ankit: But, jQuery does not return an array. – Felix Kling Commented Jul 30, 2013 at 9:03
- possible duplicate of JQuery .each() backwards – Felix Kling Commented Jul 30, 2013 at 9:04
-
Lets check
ordering
from this question: stackoverflow./questions/2351635/… – Maxim Zhukov Commented Jul 30, 2013 at 9:04
4 Answers
Reset to default 12Try
$("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);
});
$($("div[class*='TID_']").get().reverse()).each(function() {
console.log(this);
});
Working Example http://jsfiddle/yBZT6/
If your items are ordered in a descendant way all you need to do is a reverse each. You can do it - as proposed in this response - like this:
$($("div[class*='TID_']").get().reverse()).each(function() { /* ... */ });
本文标签: javascriptHow to start each from div id small to biggest numberStack Overflow
版权声明:本文标题:javascript - How to start .each from div id small to biggest number? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741970481a2407806.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论