JavaScript RegExp to CamelCase a hyphened CSS property

后端 未结 6 1202
心在旅途
心在旅途 2021-02-19 12:47

I am trying to change CSS properties like this one.

-moz-border-radius

To the JavaScript CSS property like so.

MozBorderRadius
         


        
6条回答
  •  我在风中等你
    2021-02-19 13:30

    You need to pass a callback function instead of a string.

    For example:

    var exp = /-([a-z])/gi;
    console.log('-moz-border-radius'.replace(exp, 
        function(match, char, index, str) {
            return char.toUpperCase();
        }
    ));
    

提交回复
热议问题