If you do not add elements to the page so that they are in the DOM order, you can find it like this:
function withMaxId() {
var max = -1, maxe = null;
$('[id^=id').each(function() {
var idv = parseInt(this.id.replace(/^id/, ''), 10);
if (idv > max) {
max = idv;
maxe = this;
}
});
return maxe;
}
Of course, if you know more about the elements, you can replace $('*')it with something more selective.