jQuery: Setting 'style' attribute of element with object
Posted
by JamesBrownIsDead
on Stack Overflow
See other posts from Stack Overflow
or by JamesBrownIsDead
Published on 2010-05-04T04:16:31Z
Indexed on
2010/05/04
4:28 UTC
Read the original article
Hit count: 321
I saw this in our codebase the other day:
link.attr('style', map({
color: '#9a4d9e',
cursor: 'default'
}));
map
is defined as:
function map(map) {
var cssValue = [];
for (var o in map) {
cssValue.push(o + ':' + map[o] + ';')
}
return cssValue.join(';');
}
Is map
necessarily? Is there a shorter way to do this?
It's important to note that the "style" attribute overrides any styles set by a class added/defined in the "class" attribute.
© Stack Overflow or respective owner