samedi 16 juin 2018

how do I add a checkbox before every list Item, and a delete button after the list item?

I created a to do list with HTML/Javascript. How do add a checkbox on the left of every Item added to the list and a X button to the right of every item added to delete it from the list. This is what I got so far

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>To-Do List</title>


</head>
<>
<h1>To-Do List</h1>

<form onsubmit="return addItem('list', this.inputItem)">
    <input type="text" id="inputItem" onfocus="this.value=''" onselect="this.value=''" placeholder="Enter a Task">
    <input type="submit">

</form>

<ul id="list">

</ul>

<script>

    var inputItem = document.getElementById("inputItem");
    inputItem.focus();

    // adds input Item to list
    function addItem(list, input) {
    var inputItem = this.inputItem;
    var list = document.getElementById(list);
    var listItem = document.createElement("li");
    listItem.innerText = input.value;
    list.appendChild(listItem);
    inputItem.focus();
    inputItem.select();
    return false; 

}</script>

</body>
</html>




Aucun commentaire:

Enregistrer un commentaire