Hello,
I tried several gambiarras (unfortunately) but I can not find a solution to my idea.
I have an "app" that creates a task list, only I would like to add to my list a different id for each div
added inside the div
main%.
var main = function(){
$('button').click(function(){
var tarefa = $('input[name=tarefa]').val();
var conferir = $('.item').text();
if(tarefa==conferir){
alert("Tarefa já foi adicionada!");
}
//Adiciona um div com o id item dentro do div com classe lista-tarefa
$('.lista-tarefa').append('<div id="item">' + tarefa + '</div>');
$('input[name=tarefa]').val('');
})
$(document).on('click', '.item', function(){
if (confirm("Deseja apagar?")){
$(this).remove();
}
})
}
$(document).ready(main)
In the comment part it will always add a div
with the id equal, however I would like to add with different id to be able to do a repeat validation when the user enters the task.
In practice I'd like to add a div with id="item1"
, id="item2"
, and so on.