css - How find out which stylesheets were applied (check via javascript)? -


if have 2 stylesheets set media queries:

<link rel='stylesheet' media='only screen , (min-width: 64.1em)' href='desktop.css' /> <link rel='stylesheet' media='only screen , (max-width: 64em)' href='mobile.css' /> 

and i'm looking class in document.stylesheets, how able ignore non-active stylesheet?

for example:

//pseudo-code ( var = 0; < document.styelsheets.length; i++ ) if ( document.styelsheets[ ].isapplied ) ... 

is there way know?

there's nice js feature called window.matchmedia(), can used test if media query matches viewport, example:

if(window.matchmedia('only screen , (min-width: 64.1em)').matches) {     //match } else {     //don't match } 

if can iterate through link tags, test each media attribute , check if applied.

mdn .matchmedia() docs


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -