How to find the highest data-attribute with js/jquery and append a div to it
javascript, jquery
Solution
demo
var num = $(".item").map(function() {
return $(this).data('number');
}).get();//get all data values in an array
var highest = Math.max.apply(Math, num);//find the highest value from them
$('.item').filter(function(){
return $(this).data('number') == highest;//return the highest div
}).append( $( "<div class='highest'></div>" ));//append to that div
Problem
How do you append a div to the div with the highest data attribute data-number? ``` $( ".item" ).append( $( "<div class='highest'></div>" ) ); <div id="container"> <div class="item" data-number="13"></div> <div class="item" data-number="22"></div> <div class="item" data-number="142"></div> <div class="item" data-number="2"></div> <div class="item" data-number="44"></div> </div> ```