I would suggest to correct the code on a similar
<div class="" id=""> <div class="mes " id="pm2509" data-id="2509"> text </div> <div class="mes " id="pm2511" data-id="2511"> text </div> <div class="mes " id="pm2513" data-id="2513"> text </div> <div class="mes " id="pm2515" data-id="2515"> text </div> <div id="new"></div> </div>
and then in js
var $max = null; $('.mes').each(function(){ if(!$max || $max.data('id') < $(this).data('id')){ $max = $(this); } }); //Π·Π΄Π΅ΡΡ Π² $max ΠΈΡΠΊΠΎΠΌΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ
well, or if you do not intend to change html, then
var $max = null; $('.mes').each(function(){ $(this).data('id', $(this).attr('id').replace('pm','')); if(!$max || $max.data('id') < $(this).data('id')){ $max = $(this); } }); //Π·Π΄Π΅ΡΡ Π² $max ΠΈΡΠΊΠΎΠΌΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ
data-id="2511"
and store these IDs in it. sampling (or filtering) in this case will be more reliable and transparent. - Ivan Pshenitsyn