Find the biggest from the unordered list or ordered list

Yesterday I came around the situation to find the biggest li from the list of unordered list (UL). I have done that. And added a class which is the bigger in the list. Same can be apply to the ordered list (OL) too. I think it will be helpful for the others too. It is using jQuery as javascript framework. 

If you have any questions or alternate solutions please let me know.

The code:









  • 123
  • 1234
  • 123456789
  • 12345

Download the source

Tags: , , ,

2 Responses to “Find the biggest from the unordered list or ordered list”

  1. Myhtmlworld completed 6 months | Sunil's blog Says:
    May 1st, 2009 at 10:25 pm

    [...] Find the biggest from the unordered list or ordered list [...]

  2. Shuja Shabandri Says:
    May 24th, 2009 at 3:05 am

    Alternate method would be

        $(document).ready(function() {
            var biggest = 0;
            var bigIndex = 0;
            $("#list li").each(function(i,el){
                var val = parseInt($(el).text());
                if(val > biggest) {
                    biggest = val;
                    bigIndex = i
                }
            });
            alert("postion "+ (bigIndex + 1) + " is the biggest");
            $("#list li").eq(bigIndex).addClass('bigger');
        });
    

Leave a Reply

You must be logged in to post a comment.