I have a small function that will take a string of css (eg background: red; width: 145px; height: 145px;)
and return a CSSStyleDeclaration but if I have a background property (and background-color etc) theCSSStyleDeclaration will have background-color etc set as undefined in Firefox.
_parseCSS: function(css) {
var div = document.createElement('div');
div.innerHTML = '<div style="' + css + '"></div>';
return div.childNodes[0].style
}
does anyone know what I’m doing wrong?
EDIT: here’s the code that doesn’t work with Firefox:
style: function(style) {
var css = this._parseCSS(style);
return this.each(this._elem, function(element) {
this.each(css, function(s) {
var prop = s;
element.style[prop] = css[s];
});
});
},
the parameter style is the string of css.
I think it’s because hyphenated style attributes are not the same in javascript meaning,
background-colorisbackgroundColorin javascript. So,element.style.background-colorshould beelement.style.backgroundColor.