Consider the following HTML:
var max = null;
$('.a').each(function() {
var x = +($(this).attr('x'));
if (max === null || x > max)
max = x;
}
alert(max === null ? "No matching elements found" : "The maximum is " + max);
Note the unary + operator to convert the attribute to a number. You may want to add some error checking to ensure it actually is a number - and that the attribute exists at all. You could change the selector to only select elements with the class and the attribute: $('.a[x]').