Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Change font size in multiple classes Date: Mon, 07 Sep 2015 03:33:51 +0200 Organization: PointedEars Software (PES) Lines: 71 Message-ID: <7102025.hhzk33F4p0@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1441589840 2013 eJwVxsEBwCAIA8CVRAngOCJk/xFaX3dYJnZdDaYgmD5dubv+IynmcbVO+YaMfuQaaEHklGR8J/wRRw== (7 Sep 2015 01:37:20 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 7 Sep 2015 01:37:20 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwQkBwDAIA0BL4wktcggU/xJ2BwuJPh4Ix2JpU+16H4fCj5b58HiWqmxGm2xUYS0rx4WrA2n7qEjr+wOL4Bab Cancel-Lock: sha1:cberuT14PbAmp3jgO+zgw1Ggob8= X-NNTP-Posting-Host: eJwFwYEBACAEBMCVyPMZJ8r+I3TnFhpNhAd8fHLoS1aeNtFtANHnUiv52jQ571aXwOQSe30KxBCh Xref: csiph.com comp.lang.javascript:28656 Andrew Poulos wrote: > I'm now trying this and it seems to be ok (not working in IE 8): > > > var i, > j, > len, > rules; > > for (j = 0; j < document.styleSheets.length; j++) { The number of stylesheets does not change during the loop, does it? > rules = document.styleSheets[j].cssRules; (I will forever wonder why people find this ripping apart of declaration and initialization, and the duplication of identifiers, better than the the compact variant, but anyhow:) This does not work in IE 8 because earlier MSHTMLs do not support the “cssRules” property, but the “rules” property instead. > len = rules.length; > for (i = 0; i < len; i++) { > if ( /font-size/.test(rules[i].cssText) ) { You are doing pattern matching on a serialization of what was already parsed. It should be more efficient to determine whether the “font-size” property was declared instead. Apparently the short-hand property equals the empty string, and the getPropertyValue() method returns “null”, in Blink, if the property has not been declared; both DOM 2 Style CSS and CSSOM specify it should be the empty string. However, both values are type-converted to “false”. > rules[i].style.fontSize = > (parseInt(rules[i].style.fontSize, 10) / 16) + "em"; The value of the font-size property is a CSS /length/, consisting of a *floating-point value* and a unit (that is optional if the value is zero). Use parseFloat() instead. > } > } > } > > document.body.style.fontSize = "100%"; > > > I search for font-size rules and then convert any to EMs based on 16 > pixels equals 1 em (the app only ever publishes font sizes in pixels). “16px” equals “1em” only if the user or you, for your document, have 16px set as base font-size, and an ancestor element has not set a different font- size (“em” is a *relative* unit, whose value equals the one-hundredth part of a “%” value; cf. “rem”). (Since you are overriding the original font- size value of the “body” element, you would need to set the font-size of the “html” element to “16px”. But do that only as a last resort.) -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.