
Today now in this blog i will you how to get max attribute value in jquery. Sometimes, we has a many tag also with same class and attribute also with value, but we need to find the maximal value of the attribute from that common class, Now In the bellow we have same html tag:
<ul>
<li class="test" data-id="3">hi</li>
<li class="test" data-id="5">hey</li>
<li class="test" data-id="1">hello</li>
</ul>
So now, we require to get the max value, i mean we need to 5, because that is the big value from other, so we can get maximal value from this way:
var max = 0;
$('.test').each(function() {
var value = parseInt($(this).data('id'));
max = (value > max) ? value : max;
});
alert(max);
Read Also : Laravel and AngularJS CRUD with Search & Pagination Example
Thanks for read. I hope it help you. For more you can follow us on facebook.