How to Get Max Attribute Value in JQuery?
In this profound tutorial, we will learn jquery get max attribute value. let’s discuss about jquery get custom attribute value by class. I would like to show you jquery find max attribute value. step by step explain find maximum value of attribute 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 conman class, In bellow you have same HTML tag:
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:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<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>
<script type="text/javascript">
var max = 0;
$('.test').each(function() {
var value = parseInt($(this).data('id'));
max = (value > max) ? value : max;
});
alert(max);
</script>
</body>
</html>
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- JQuery Radio Button Change Event Example
- JQuery Remove Multiple Values from Array Example
- Calculate Number of Days Between Two Dates in JQuery
- JQuery Get Selected Dropdown Value on Change Event Example
- How to Disable Text Selection using JQuery?
- How to Get Selected Radio Button Value in JQuery?
- JQuery Redirect to Another Page After 5 Seconds Example
- Add Edit Delete Table Row Example using JQuery
- How to Disable Browser Back Button using JQuery?
- How to Remove Duplicate Object from Array in JQuery?
- JQuery Datepicker Example using JQuery UI JS
- How to Convert Line Breaks to br in jQuery ?