Skip to content

Instantly share code, notes, and snippets.

@Gioni06
Created October 31, 2014 13:52
Show Gist options
  • Save Gioni06/a9e8f1f304284de1e2e3 to your computer and use it in GitHub Desktop.
Save Gioni06/a9e8f1f304284de1e2e3 to your computer and use it in GitHub Desktop.
Remove CSS and JS Files
function removejscssfile(filename, filetype){
var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
var allsuspects=document.getElementsByTagName(targetelement)
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
}
}
removejscssfile("admin","css");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment