Cool Jquery action with TO DO list

used append() and on() functions

by Mehmetcan Sinir

HTML

<!--we will now create a form and get its elements with Jquery-->
<title>To Do</title>
<body>
     <h2>To Do</h2>

    <form name="checkListForm">
        <input type="text" name="checkListItem" />
    </form>
    <div id="button">Add!</div>
    </br>
    <div class="list"></div>
</body>

CSS

h2 {
    font-family: arial;
}
form {
    display: inline-block;
}
#button {
    display: inline-block;
    height: 20px;
    width: 70px;
    background-color: #cc0000;
    font-family: arial;
    font-weight: bold;
    color: #ffffff;
    border-radius: 5px;
    text-align: center;
    margin-top: 2px;
}
.list {
    font-family: garamound;
    color: cc0000;
}

JavaScript

$(document).ready(function () {
    //call the click function for the #button div 
    $("#button").click(function () {
        //store user input in the form to a variable named addTo
        var toAdd = $("input[name=checkListItem]").val();
        //on click append addTo inside a div to the #list div 
        $(".list").append('<div class="item">' + toAdd + '</div>');
    });
    //with the on() function, arguments are: when to do it, what is the target, and what to do
    $(document).on('click', '.item', function() {
        //when clicked on the item, item is removed
        $(this).remove();//this is the item
    });
});