Consider the following HTML:
<div class="a" x="6"></div> <div class="a" x="9"></div> <div class="a" x="2"></div> ... <div class="a" x="8"></div>
How would you find the maximal x
value of all .a
elements ?
Assume that all x
values are positive integers.
Advertisement
Answer
Just loop over them:
var maximum = null; $('.a').each(function() { var value = parseFloat($(this).attr('x')); maximum = (value > maximum) ? value : maximum; });