Skip to content

Instantly share code, notes, and snippets.

@bill-barron
Last active April 3, 2019 09:26
Show Gist options
  • Save bill-barron/5140242 to your computer and use it in GitHub Desktop.
Save bill-barron/5140242 to your computer and use it in GitHub Desktop.
Remove elements and unload scripts from the page without jQuery. Works with IE8+. See: http://caniuse.com/#feat=queryselector for compatability. You can use this script like so: remove(selector) or remove([selector, selector, selector, ...]) or remove(element) or remove('script, style');
(function (scope) {
var remove = function (selector) {
if(selector instanceof Element && selector.parentElement)
selector.parentElement.removeChild(selector);
if(typeof selector === "string" && document.querySelectorAll) {
var list = document.querySelectorAll(selector)
for(var i = 0; i < list.length; i += 1)
remove(list[i]);
}
};
scope.remove = remove;
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment