<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: currentstyle code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 04:31:00 GMT</pubDate>
    <description>DZone Snippets: currentstyle code</description>
    <item>
      <title>Cross-browser way to retrieve styles for elements via the DOM</title>
      <link>http://snippets.dzone.com/posts/show/2921</link>
      <description>document.getElementById('whatever').style only gives local styles, but if you want those specified in external CSS definitions, you have to arse about (why, oh, why?) and do it like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function newGetStyle(nodeName, sStyle) {&lt;br /&gt;	var x = document.getElementById(nodeName);&lt;br /&gt;	var y;&lt;br /&gt;	if (x.currentStyle) {&lt;br /&gt;		y = x.currentStyle[sStyle];&lt;br /&gt;	} else {&lt;br /&gt;		try {&lt;br /&gt;		y = document.defaultView.getComputedStyle(x,null).getPropertyValue(sStyle);&lt;br /&gt;	  } catch(e) { }&lt;br /&gt;	}&lt;br /&gt;	return y;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 29 Oct 2006 21:02:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2921</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
