Javascript Homeworks/Homework2/js/toDo.js
// Create a new list item when clicking on the "Add" button
Create a new list item when clicking on the "Add" button
Create a new list item when clicking on the " Add " button
function newElement() {
  var li = document.createElement("li");
  var inputValue = document.getElementById("task").value;
  var t = document.createTextNode(inputValue);
  li.appendChild(t);
  if (inputValue.trim().length  == 0) {
    $(".error").toast("show");
  } else {
    $(".success").toast("show");
    document.getElementById("list").appendChild(li);
  }
  document.getElementById("task").value = "";
  var span = document.createElement("SPAN");
  var txt = document.createTextNode("\u00D7");
  span.className = "close";
  span.appendChild(txt);
  li.appendChild(span);
  for (i = 0; i < close.length; i++) {
    close[i].onclick = function () {
        var div = this.parentElement;
        var ul = div.parentElement;
        ul.removeChild(div)
        $(".delete").toast("show")
    };
  }
}
function newElement ( ) { var li = document . createElement ( "li" ) ; var inputValue = document . getElementById ( "task" ) . value ; var t = document . createTextNode ( inputValue ) ; li . appendChild ( t ) ; if ( inputValue . trim ( ) . length == 0 ) { $ ( ".error" ) . toast ( "show" ) ; } else { $ ( ".success" ) . toast ( "show" ) ; document . getElementById ( "list" ) . appendChild ( li ) ; } document . getElementById ( "task" ) . value = "" ; var span = document . createElement ( "SPAN" ) ; var txt = document . createTextNode ( "\u00D7" ) ; span . className = "close" ; span . appendChild ( txt ) ; li . appendChild ( span ) ; for ( i = 0 ; i < close . length ; i ++ ) { close [ i ] . onclick = function ( ) { var div = this . parentElement ; var ul = div . parentElement ; ul . removeChild ( div ) $ ( ".delete" ) . toast ( "show" ) } ; } }
Create a new list item when clicking on the "Add" button
Create a new list item when clicking on the " Add " button