Q:

RemoveChild error for some id

few hours I try to know why sometimes my removechild don't work. After reading the forum I see some issue about the fact my removechild array reduce is number each time... But I don't know how to fix this issue... Do you have any idea?
EDIT: I justed updated the snippets
For replicate the issue I invite you to add 4 new div and delete the third one and the try to delete the others... One of them will cause some troubles

function newText() {
  var text = prompt("Merci d'entrer une tache");
  if (text != "") {
    addElement(text);
  }
}

function deletediv(id) {
  var parent = document.getElementById('ft_list');
  parent.removeChild(parent.childNodes[id]);

}

function addElement(text) {
  var id = document.getElementById('ft_list').children.length
  var ref = document.getElementById(id);
  if (id == "")
    id = 1;
  else
    id++;
  var newDiv = document.createElement('div');
  newDiv.setAttribute('class', "line");
  newDiv.setAttribute('id', id);
  newDiv.setAttribute('onclick', 'deletediv(this.id);');
  var newContent = document.createTextNode(text);
  newDiv.appendChild(newContent);
  document.getElementById("ft_list").insertBefore(newDiv, ref);
}
#ft_list {
  border: 1px dashed lightgrey;
  min-height: 30vh;
}
.line {
  background: lightgrey;
  padding: 5px;
  margin: 5px
}
input {
  background: lightgrey;
  width: 150px;
  height: 50px;
}
<input type="submit" name="submit" value="New" onclick="newText()">
<div id="ft_list">

</div>

A:

You are accessing the element as the index of parent's childNodes but if you delete a record and then add again, it won't skip the added records counter value.
Instead of passing the id, pass the element itself
newDiv.setAttribute('onclick', 'deletediv(this);');

and change the method as
function deletediv(el) {
  el.parentNode.removeChild(el);
}

Demo

function newText() {
  var text = prompt("Merci d'entrer une tache");
  if (text != "") {
    addElement(text);
  }
}

function deletediv(el) {
  el.parentNode.removeChild(el);
}

function addElement(text) {
  var id = document.getElementById('ft_list').children.length
  var ref = document.getElementById(id);
  if (id == "")
    id = 1;
  else
    id++;
  var newDiv = document.createElement('div');
  newDiv.setAttribute('class', "line");
  newDiv.setAttribute('id', id);
  newDiv.setAttribute('onclick', 'deletediv(this);');
  var newContent = document.createTextNode(text);
  newDiv.appendChild(newContent);
  document.getElementById("ft_list").insertBefore(newDiv, ref);
}
#ft_list {
  border: 1px dashed lightgrey;
  min-height: 30vh;
}
.line {
  background: lightgrey;
  padding: 5px;
  margin: 5px
}
input {
  background: lightgrey;
  width: 150px;
  height: 50px;
}
<input type="submit" name="submit" value="New" onclick="newText()">
<div id="ft_list">

</div>

