最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

remove css file with javascript - Stack Overflow

programmeradmin4浏览0评论

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 0
Add a ment  | 

3 Answers 3

Reset to default 10

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();

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/

发布评论

评论列表(0)

  1. 暂无评论