im trying now to:
this value DONE4. and set the max value parent background to for example background: #000;
So my question is how i gonna get a parent of the MAX value what was calculated before?
CODEPEN DEMO
$('.views').each(function(){
valText = $(this).text();
$(this).attr('value', valText);
});
var numbers = $(".views").map(function(){
return parseFloat(this.getAttribute('value')) || -Infinity;
});
var calculate = Math.max.apply(Math, numbers);
$("#max").html(calculate);
<div><div class="views" >10</div></div>
<div><div class="views" >1</div></div>
<div><div class="views" >7</div></div>
<div><div class="views" >5</div></div>
<div><div class="views" >3</div></div>
Max value is:
<p>Max value is: <span id="max"></span></p>
Being a little tricky, reducing the collection to the one with the highest number inside
var el = $('.views').toArray().reduce(function(a,b) {
return (+$(a).text()) > (+$(b).text()) ? $(a) : $(b);
});
FIDDLE
To get the parent, simply
el.parent();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With