JavaScript: Deleting a DOM element

From The Travis van der Font Wiki
Jump to: navigation, search
Example HTML element:
<div id="example_name">test</div>
To remove the <div> from the DOM tree entirely:
document.getElementById('example_name').remove();
If remove() isn't support by the client browser, then use this function below:
function removeElement(id)
{
    var element = document.getElementById(id);

        element.parentNode.removeChild(element);
}

removeElement('example_name');
Using jQuery:
$('#example_name').remove();