How to get max attribute value in jquery?

How to get max attribute value in jquery

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:

	<li class="test" data-id="3">hi</li>
	<li class="test" data-id="5">hey</li>
	<li class="test" data-id="1">hello</li>

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;

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.


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →