0

now i am using jquery to get ids of ul and li from top to bottom .but i cant able to get it from bottom to top . iam using the following code

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

 <script type="text/javascript">

        function next_click()
        {
        alert("next");
        var toHighlight = jQuery('.current').next().length > 0 ? jQuery('.current').next() : jQuery('#men_shirt li').first();
        jQuery('.current').removeClass('current');
        toHighlight.addClass('current');
        $('#men_shirt ul li').each(function(i)
        {
           var iid=$(this).attr('id'); 
           alert("sdfsdf"+iid);
        });

        var a=jQuery('li').hasClass('current');
        alert(a);

        if(a=='style')
        {
        set_menuselected('Style');
        }
        } 

</script>

Please advise on this

Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
saravanan
  • 401
  • 1
  • 4
  • 11

2 Answers2

1

Use .get().reverse() See Help

$.each('#men_shirt ul li').get().reverse(),function(i)//use get.reverse method()
{
   var iid=$(this).attr('id'); 
   alert("sdfsdf"+iid);
});
Community
  • 1
  • 1
Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51
0

You can extend jQuery with the reverse method:

jQuery.fn.reverse = [].reverse;

And then:

$('#men_shirt ul li').reverse().each(function() {
    ...
});
sdabet
  • 18,360
  • 11
  • 89
  • 158