Skip to content

Instantly share code, notes, and snippets.

@fisknils
Last active August 29, 2015 14:21
Show Gist options
  • Save fisknils/a62c1fd98f5163018503 to your computer and use it in GitHub Desktop.
Save fisknils/a62c1fd98f5163018503 to your computer and use it in GitHub Desktop.
just some javascript- functions I find myself often using for greasemonkey- scripts
// Some convenience- functions for removing elements
function removeElementByXpath(xpath) {
return removeElement(getElementByXpath(xpath));
}
function getElementByXpath(xpath) {
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function removeElement(element) {
return element.parentNode.removeChild(element);
}
function removeElementById(id) {
return removeElement(document.getElementById(id));
}
function removeElementsByClassName(className) {
var elements = document.getElementsByClassName(className);
for(var i in className) {
removeElement(elements[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment