Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove css file with javascript

Tags:

javascript

css

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 ?

like image 624
Young Avatar asked Aug 31 '26 08:08

Young


1 Answers

Remove 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();
like image 111
Blaise Avatar answered Sep 02 '26 14:09

Blaise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!