Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #34042 > unrolled thread

Media CSS Rules

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2017-09-28 13:31 +1000
Last post2017-09-28 10:10 +0200
Articles 3 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  Media CSS Rules Andrew Poulos <ap_prog@hotmail.com> - 2017-09-28 13:31 +1000
    Re: Media CSS Rules Andrew Poulos <ap_prog@hotmail.com> - 2017-09-28 13:45 +1000
      Re: Media CSS Rules "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-09-28 10:10 +0200

#34042 — Media CSS Rules

FromAndrew Poulos <ap_prog@hotmail.com>
Date2017-09-28 13:31 +1000
SubjectMedia CSS Rules
Message-ID<-IidnUN5Wfq98FHEnZ2dnUU7-RPNnZ2d@westnet.com.au>
With this

var i,
     mySheet = document.styleSheets[0];

if (mySheet.cssRules && mySheet.cssRules.length) {
   for (i = 0; i < mySheet.cssRules.length; i++) {
     console.log(mySheet.cssRules[i].selectorText)
   }
}

I'm having a look at the rules in a style sheet. The sheet has some 
rules under

@media all and (max-width: 640px) {

but these don't get listed. How do I find all the media queries and 
return the rules in each?

Ideally I need to add/delete/modify rules in media queries.

Andrew Poulos

[toc] | [next] | [standalone]


#34043

FromAndrew Poulos <ap_prog@hotmail.com>
Date2017-09-28 13:45 +1000
Message-ID<Db-dnUWZQcn_7VHEnZ2dnUU7-L_NnZ2d@westnet.com.au>
In reply to#34042
On 28/09/2017 1:31 PM, Andrew Poulos wrote:
> With this
> 
> var i,
>      mySheet = document.styleSheets[0];
> 
> if (mySheet.cssRules && mySheet.cssRules.length) {
>    for (i = 0; i < mySheet.cssRules.length; i++) {
>      console.log(mySheet.cssRules[i].selectorText)
>    }
> }
> 
> I'm having a look at the rules in a style sheet. The sheet has some 
> rules under
> 
> @media all and (max-width: 640px) {
> 
> but these don't get listed. How do I find all the media queries and 
> return the rules in each?
> 
> Ideally I need to add/delete/modify rules in media queries.

Doh. I just found that under CSSRuleList is CSSMediaRule and MDN tells 
me that CSSMediaRule is of type 4.

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#34045

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-09-28 10:10 +0200
Message-ID<XnsA7FE6777B76DDeejj99@194.109.6.166>
In reply to#34043
Andrew Poulos <ap_prog@hotmail.com> wrote on 28 Sep 2017 in 
comp.lang.javascript:

> Doh. I just found that under CSSRuleList is CSSMediaRule and MDN tells 
> me that CSSMediaRule is of type 4.

Try this [tested under Chrome beta v62]:

var i, mySheet = document.styleSheets;
  for (i = 0; i < mySheet.length; i++)
    console.log(mySheet[i]);

Gives you all sheet info [... you ever wanted upto now ;-) ].

I use it in the Shortcut manager.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web