I was wondering how can we write a jquery statement to get the max value of a property of matched elements.
in LINQ we say something like this:
var maxHeight = list.Max(a=> a.Height);
what is the best way to do this in jquery?
as an example let’s say we want to select the max numeric value of all :text elements inside a container:
var allInputs = $("#container :text");
// how to get the max of parseInt(item.val())?
of course having a loop over all elements is an option but I’m curious to know if there is a magic to do with jquery.
Regards.
Based on all the conversation here and my search in the net we can say that (at this time) there is no robust built-in jquery way to calculate .max() and .min() of a property of elements matching a selector.
From what Igor suggested I came up with the following two jquery functions which you can add to your project if you need to use .max() and .min() functionalities over and over:
See a demo here: http://jsfiddle.net/NF7v7/3/