get document.styleSheets by name instead of index?

后端 未结 5 1653
鱼传尺愫
鱼传尺愫 2020-12-25 11:20

document.styleSheets is used with an index,
but what If I want to use stylesheet.insertRule with a specific CSS file ?

I know the file\'s name, which is

5条回答
  •  北海茫月
    2020-12-25 11:43

    Why so complicated? You can get a specific document stylesheet by ID or URL without looping through all the stylesheets in the document: var mysheet = $('link#id')[0].sheet; ... or ... var mysheet = $('link[href="/css/style.css"]')[0].sheet;

提交回复
热议问题