I am trying to change CSS properties like this one.
-moz-border-radius
To the JavaScript CSS property like so.
MozBorderRadius
I am using this RegExp.
var exp = new RegExp('-([a-z])', 'gi');
console.log('-moz-border-radius'.replace(exp, '$1'));
All I need to do is convert $1 to upper case so it can cammelcaseify (yes I made that word up...) my CSS property into a JavaScript based one. Is this possible?
Thanks.
You would be better off using a function as the second parameter in replace()
, and you could also use a regex literal instead of the RegExp
constructor:
var replaced = '-moz-border-radius'.replace(/-([a-z])/gi, function(s, group1) {
return group1.toUpperCase();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With