Estou com duvida nessa parte, pois usei da mesma forma o preventDefault() para não recarregar a pagina.
Codigo HTML:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form>
<input class="input-item" type="text" placeholder="digite a tarefa que desejar">
<button class="button-item">Salvar</button>
</form>
<script src="script.js"></script>
</body>
</html>
Codigo JavaScript:
const botao = document.querySelector('.button-item');
const botaoRemover = document.querySelector('.remover-botao');
let contador = 0;
botao.addEventListener('click',salvar);
botaoRemover.addEventListener('click',removerItem);
function salvar(evento){
evento.preventDefault()
const tarefa = document.querySelector('.input-item');
const container = document.querySelector('form');
const divContainer = document.createElement('div');
const buttonEditar = document.createElement('button');
const buttonRemover = document.createElement('button');
const paragrafo = document.createElement('p');
const divButton = document.createElement('div');
const createCheck = document.createElement('input');
createCheck.type = 'checkbox';
paragrafo.innerText = tarefa.value;
buttonEditar.innerHTML = 'Editar Item';
buttonRemover.innerHTML = 'Remover Item';
createCheck.id = 'contador-' + contador++;
divContainer.classList.add('div-tarefas');
buttonRemover.classList.add('remover-botao');
container.appendChild(divContainer);
divContainer.appendChild(createCheck);
divContainer.appendChild(paragrafo);
divButton.appendChild(buttonEditar);
divButton.appendChild(buttonRemover);
divContainer.appendChild(divButton);
}
function removerItem(evento){
evento.preventDefault()
}