YUI3 (JS) setStyle using vendor prefixes

1.5k Views Asked by At

How do I use YUI3's set style to set something like -webkit-border-radius: 10px;?

example:

Y.one('#mydiv').setStyle('-webkit-border-radius', '10');
3

There are 3 best solutions below

4
On BEST ANSWER

Should work.

I think you are missing the 'px' for

Y.one('#mydiv').setStyle('-webkit-border-radius', '10');

Should be

Y.one('#mydiv').setStyle('-webkit-border-radius', '10px');
0
On

Use camel case. When DOM scripting, style properties should always be set using camelCase. Webkit is lax about that and violates spec.

Y.one('#mydiv').getDOMNode().style.setProperty('mozBorderRadius', '10');

For border-radius, it's pretty safe (these days) to skip the vendor prefix, though.

Source

0
On

In case anyone else still needs to accomplish this, here's how I did it:

Y.one('#mydiv').getDOMNode().style.setProperty('-moz-border-radius', '10');