resources/js/main.js
// Adds a new item to the todo list
Adds a new item to the todo list
Adds a new item to the todo list
function addItemToDOM(task, completed) {
  var list = (completed) ? document.getElementById('completed') : document.getElementById('todo');
  var item = document.createElement('li');
  item.innerText = task.taskname;
  item.setAttribute('data-id', task.id);
  var buttons = document.createElement('div');
  buttons.classList.add('buttons');
  var remove = document.createElement('button');
  remove.classList.add('remove');
  remove.innerHTML = removeSVG;
  remove.addEventListener('click', removeItem);
  var complete = document.createElement('button');
  complete.classList.add('complete');
  complete.innerHTML = completeSVG;
  complete.addEventListener('click', completeItem);
  buttons.appendChild(remove);
  buttons.appendChild(complete);
  item.appendChild(buttons);
  list.insertBefore(item, list.childNodes[0]);
}
function addItemToDOM ( task , completed ) { var list = ( completed ) ? document . getElementById ( 'completed' ) : document . getElementById ( 'todo' ) ; var item = document . createElement ( 'li' ) ; item . innerText = task . taskname ; item . setAttribute ( 'data-id' , task . id ) ; var buttons = document . createElement ( 'div' ) ; buttons . classList . add ( 'buttons' ) ; var remove = document . createElement ( 'button' ) ; remove . classList . add ( 'remove' ) ; remove . innerHTML = removeSVG ; remove . addEventListener ( 'click' , removeItem ) ; var complete = document . createElement ( 'button' ) ; complete . classList . add ( 'complete' ) ; complete . innerHTML = completeSVG ; complete . addEventListener ( 'click' , completeItem ) ; buttons . appendChild ( remove ) ; buttons . appendChild ( complete ) ; item . appendChild ( buttons ) ; list . insertBefore ( item , list . childNodes [ 0 ] ) ; }
Adds a new item to the todo list
Adds a new item to the todo list
// Add click event for removing the item // Add click event for completing the item