Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: Set border radius

Tags:

javascript

How can I set the -moz-border-radius with pure JavaScript (no jQuery, no plugins etc)?

document.getElementById('id')
like image 259
user199337 Avatar asked Nov 25 '09 21:11

user199337


People also ask

What is border radius in JavaScript?

The border-radius CSS property rounds the corners of an element's outer border edge. You can set a single radius to make circular corners, or two radii to make elliptical corners.

How do you define a border radius for an HTML element?

CSS Syntax border-radius: 1-4 length|% / 1-4 length|%|initial|inherit; Note: The four values for each radius are given in the order top-left, top-right, bottom-right, bottom-left. If bottom-left is omitted it is the same as top-right.

Why border radius is not working?

If there are contents within the div that has the curved corners, you have to set overflow: hidden because otherwise the child div's overflow can give the impression that the border-radius isn't working.

Can you use REM for border radius?

Border radius tokens are used to give sharp edges a more subtle, rounded effect. They use rem units so they scale with the base font size. The pixel values displayed are based on a 16px font size.


2 Answers

Try:

document.getElementById('id').style.borderRadius = '1em'; // w3c
document.getElementById('id').style.MozBorderRadius = '1em'; // mozilla

But why not do it in a stylesheet?

like image 191
Crescent Fresh Avatar answered Nov 15 '22 21:11

Crescent Fresh


var myElementStyle = document.getElementById('id').style;

myElementStyle.borderRadius = '1em'; // standard
myElementStyle.MozBorderRadius = '1em'; // Mozilla
myElementStyle.WebkitBorderRadius = '1em'; // WebKit
like image 25
Eli Grey Avatar answered Nov 15 '22 21:11

Eli Grey