JavaScript: Clear ListView or all contents in a div

If  you need to all items in a HTML ListView or div using JavaScript, below is a useful function to do so.
The function basically get the element and if the element exist proceed to remove all of its child nodes.

function ClearList(listId) {
    var el = document.getElementById(listId)

    if (el) {
        while (el.hasChildNodes()) {
            el.removeChild(el.childNodes[0]);
        }
    }
}
Advertisements
JavaScript: Clear ListView or all contents in a div

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s