I'm sorry for an incomplete answer but I usually only work with JQuery not pure JavaScript. I Have made a JsFiddle which adds a remove click. You just need to find out how to remove the above sibling (the added text box).
Here is the code I added.
var foo = document.getElementById("fooBar");
var btn = document.createElement("a");
btn.href = '#';
btn.onclick = function () {
//remove button and click here
};
var t = document.createTextNode("Remove");
btn.appendChild(t);
//Append the element in page (in span)
foo.appendChild(element);
foo.appendChild(btn)