A method to get the styles for an element that aren’t set in-line or with JavaScript. Apply this function to get the desired result.
Source code for webtoolkit.computestyle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/**
*
* Compute not inline styles
* http://www.webtoolkit.info/
*
**/
function getStyle(el, property) {
if (!el) { return null; }
if (el.currentStyle) {
var tmp = property.split('-');
property = tmp[0];
for (var i = 1; i < tmp.length; i++) {
property += tmp[i].slice(0, 1).toUpperCase() + tmp[i].slice(1);
}
return el.currentStyle[property];
} else if (window.getComputedStyle) {
return document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
}
return null;
}
|