Add a button to delete a task from my to-do list

Asked

Viewed 64 times

0

Add an "X" button next to each task, which when activated it deletes this task.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Lista de Tarefa</title>
</head>
<body>
    <h1>Lista de Tarefa</h1>

    <input type="text" id="text" class="text" placeholder="Tarefa">

    <ul id="lista" class="lista"> </ul>

    <button onclick="adicionar()" id="adicionar">ADICIONAR</button>

    <script>
        function adicionar()
{
    let text = document.getElementById('text').value;
    let list = document.getElementById('lista').innerHTML;

    list += `<li> ${text}</li>`
    document.getElementById('lista').innerHTML = list;
}



    </script>
</body>
</html>

  • Please clarify your problem or provide additional details in order to highlight exactly what you need. The way it’s written these days it’s hard to tell exactly what you’re asking.

  • Avoid using onclick. Use addEventListener.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.