SO Question - Remove Item

http://stackoverflow.com/q/25222765/940217

by some

HTML

<input type="text" id="input" />
<button id="displayList">display list</button>
<button id="removeItem">remove item</button>
<ul id="list"></ul>
<ul id="newList"></ul>

JavaScript

var carBrands = ["Toyota", "Honda", "BMW", "Lexus", "Mercedes", "Peugeot", "Aston Martin", "Rolls Royce"];


var itemToRemove;

$(document).ready(function () {
    console.log("Ready to go!");
    $("#displayList").bind('click', function (event) {
        displayList();
    });
    $("#removeItem").bind('click', function (event) {
        item = document.getElementById("input").value;
        removeItemFromList(item);
    });
    displayList();
});

function displayList() {
    var
        child,
        list = document.getElementById("list"),
        frag = document.createDocumentFragment();
    carBrands.forEach(
        function (car) {
          var li = document.createElement('li');
          li.textContent = car;
          frag.appendChild(li);
        }
    );
    
    while (child = list.lastChild) {
        list.removeChild(child);
    }
    list.appendChild(frag);
}

function removeItemFromList(item) {
    var pos = carBrands.indexOf(item);
    if (pos < 0) return;
    carBrands.splice(pos,1);
    displayList();
}