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.
Comments
Post a Comment