I've implemented an HTML task board. When the user press on the "Save" button - then the JS code adds the user task into a container. Each task container has a "Remove" button, But when pressing on it - it deletes the first container child.
codes:
The "Save" button code:
var mission =
{
text: document.getElementById('textarea').value,
date: document.getElementById('date').value,
time: document.getElementById('time').value
};
const rows = document.getElementById('rows');
const cell = document.createElement('div');
const id = document.createAttribute('id');
id.value = "div-cell";
cell.setAttributeNode(id);
cell.innerHTML = '<button id="remove-button" type="button" class="btn btn-default" aria-label="Right Align" onClick="removeButton()"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button><textarea></textarea><div><input><input></div>';
rows.appendChild(cell);
const [textarea, dateinput, timeinput] = cell.querySelectorAll('textarea, input');
textarea.value = mission.text;
dateinput.value = mission.date;
timeinput.value = mission.time;
The "remove" button code:
function removeButton(){
document.getElementById('rows').removeChild(document.getElementById('div-cell'));
}
I do understand that my code - looks for the first child and removes it. Can someone tell me how to remove the container which was pressed and not the first.
I thought about an array, but I've no idea how to implement it.
Thanks for the helpers