Good morning, I am putting together a system that when I click a button I add a <li>
to the last row record, however every <li>
has numeric data-id for differentiation, that is, I would need to know the last data-id to be able to add +1 by clicking the button.
I tried as a code below but it did not work, it just takes the first data-id (I need the latter) and does not add + 1 on the second click,
$("#botaoexemplo").on("click", function() {
var contagem = $('.dd-item').attr('data-id');
contagem++;
$("#dd-list-geral").append('<li class="dd-item" data-id="'+contagem+'"><div class="dd-handle"> Item 100 </div></li>');
console.log(valor, dado);
});