Last active
April 3, 2019 09:26
-
-
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');
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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