Is there a way in jQuery to get all CSS from an existing element and apply it to another without listing them all?
I know it would work if they were a style attribut
@marknadal's solution wasn't grabbing hyphenated properties for me (e.g. max-width
), but changing the first for
loop in css2json()
made it work, and I suspect performs fewer iterations:
for (var i = 0; i < css.length; i += 1) {
s[css[i]] = css.getPropertyValue(css[i]);
}
Loops via length
rather than in,
retrieves via getPropertyValue()
rather than toLowerCase().