Why won't .getPropertyValue () return the value of the "borderRadius" property?

Here is the function:

function lastmenuborder() {
    var articleparent = document.getElementById('article').parentNode;
    var articlestyle = window.getComputedStyle(articleparent,null).getPropertyValue('borderRadius');
    alert (articlestyle);
}

I do not get the value, but css for the parent node:

div#mainbody div.placeholder {
    border-radius: 3px;
}

What do I need to change to return "3px"? All help is much appreciated; I am still new to JavaScript.

+5
source share
2 answers

For getPropertyValue()you use a hyphen instead of camelCase.

This works in Chrome ...

.getPropertyValue('border-radius');

But Firefox seems to require certain angles using this syntax ...

.getPropertyValue('border-top-left-radius');
+8
source

getComputedStyle is not supported in IE8 below to fix this usage:

if (!window.getComputedStyle) {
       window.getComputedStyle = function(el, pseudo) {
           this.el = el;
               this.getPropertyValue = function(prop) {
               var re = /(\-([a-z]){1})/g;
               if (prop == 'float') prop = 'styleFloat';
               if (re.test(prop)) {
                   prop = prop.replace(re, function () {
                       return arguments[2].toUpperCase();
                   });
               }
               return el.currentStyle[prop] ? el.currentStyle[prop] : null;
           }
           return this;
       }
   }

var elem = window.getComputedStyle(document.getElementById('test'), "");
alert(elem.getPropertyValue("borderRadius"));
0
source

All Articles