I'm trying to remove css file from document.
ths should work.. ==>
document.getElementsByTagName("link")[1].remove();
but, not working. and when I add some testing code. ==>
document.getElementsByTagName("link")[1].remove();
console.log(document.getElementsByTagName("link")[1].remove());
it's working now.
what is the problem.. or what do I miss ?
I'm trying to remove css file from document.
ths should work.. ==>
document.getElementsByTagName("link")[1].remove();
but, not working. and when I add some testing code. ==>
document.getElementsByTagName("link")[1].remove();
console.log(document.getElementsByTagName("link")[1].remove());
it's working now.
what is the problem.. or what do I miss ?
Share Improve this question asked Jun 6, 2014 at 17:01 YoungYoung 9791 gold badge8 silver badges18 bronze badges 03 Answers
Reset to default 10Remove is not a DOM node method. Maybe you confused it with the jQuery method?
Either use plain JavaScript:
var linkNode = document.getElementsByTagName('link')[1];
linkNode.parentNode.removeChild(linkNode);
Or jQuery:
$('link').eq(1).remove();
much clear selection
use querySelector instead of getElementsByTagName
var linkNode = document.querySelector('link[href*="whatever.css"]');
i would suggest jquery .removeClass() function. this can remove one or more classes assigned to any specified element or tag.
see documentation here http://api.jquery./removeclass/