How to get max attribute value in jquery?

By Hardik Savani | February 23, 2016 | Category : Javascript HTML jQuery

Sometimes, you have a many tag with same class and attribute with value, but you need to find maximal value of attribute from that comman class, In bellow you have same html tag:


<li class="test" data-id="3">hi</li>

<li class="test" data-id="5">hey</li>

<li class="test" data-id="1">hello</li>


Now, you require to get max value, i mean you need to 5, because that is big value from other, so you can get maximal value from this way:

var max = 0;

$('.test').each(function() {

var value = parseInt($(this).data('id'));

max = (value > max) ? value : max;



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.