Find the biggest from the unordered list or ordered list
Posted by Sunil | Filed under Web Development
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
Tags: Biggest li, formatting UL li, formatting unordered list, JQuery
2 Responses to “Find the biggest from the unordered list or ordered list”
Leave a Reply
You must be logged in to post a comment.












May 1st, 2009 at 10:25 pm
[...] Find the biggest from the unordered list or ordered list [...]
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'); });