0

I have the following function, which fills the list with items. But I also would like to create a function, which clears the whole content of the list, how should I do it?

Here is the function itself:

function listFiller() {
    var list = document.getElementById('list');
    var entry = document.createElement('li');
    entry.appendChild(document.createTextNode(guessedWord));
    entry.appendChild(document.createTextNode(" - "));
    entry.appendChild(document.createTextNode(seconds));
    list.appendChild(entry);
}

Also, how could I specify that the items should be added to the top of the list?

1 Answer 1

1
function clearList() {
    var list = document.getElementById('list');
    while(list.lastChild) {
        list.removeChild(list.lastChild);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.