setAttribute, style and Internet Explorer (IE)
- Data:
- 4 September 2008
- Kategoria:
- Programowanie
Trying to take advantage of ever javascript functions setAttribute ( 'style', 'properties'), and you had not worked in Internet Explorer? No precisely. And this is because IE does not support it in its entirety and incomplete implemented.
However, there is a simple solution from peterbe.com:
function rzCC(s){
// thanks http://www.ruzee.com/blog/2006/07/\
// retrieving-css-styles-via-javascript/
for(var exp=/-([a-z])/;
exp.test(s);
s=s.replace(exp,RegExp.$1.toUpperCase()));
return s;
}
function _setStyle(element, declaration) {
if (declaration.charAt(declaration.length-1)==';')
declaration = declaration.slice(0, -1);
var k, v;
var splitted = declaration.split(';');
for (var i=0, len=splitted.length; i<len; i++) {
k = rzCC(splitted[i].split(':')[0]);
v = splitted[i].split(':')[1];
eval("element.style."+k+"='"+v+"'");
}
}
Now, simply give element and give it the characteristics of style:
var closer = document.createElement('a');
//a.setAttribute('style', 'float:left; font-weight:bold');
_setStyle(a, 'float:left; font-weight:bold');
a.onclick = function() { ...
Leave a Reply
Kategorie
- Accessibility (16)
- Aktualności Ikeris (23)
- Artykuły (12)
- CSS (12)
- Flash (4)
- Grafika (2)
- HTML i XHTML (13)
- Oprogramowanie (6)
- Programowanie (18)
- Przeglądarki (23)
- Server side (3)
- Skrypty (7)
- Systemy (2)
- Usability (6)
- Wordpress (11)
Linki
