Last active
August 29, 2015 14:21
-
-
Save fisknils/a62c1fd98f5163018503 to your computer and use it in GitHub Desktop.
just some javascript- functions I find myself often using for greasemonkey- scripts
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
// 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