Node[removed] giving tag names in lower case

前端 未结 4 1918
眼角桃花
眼角桃花 2021-01-18 15:58

I am iterating NodeList to get Node data, but while using Node.innerHTML i am getting the tag names in lowercase.

4条回答
  •  醉话见心
    2021-01-18 16:59

    If you are trying to just capitalise the first character of the tag name, you can use:

    var s = 'panel';
    s.replace(/(^.)(.*)/,function(m, a, b){return a.toUpperCase() + b.toLowerCase()}); // Panel
    

    Alternatively you can use string manipulation (probably more efficient than a regular expression):

    s.charAt(0).toUpperCase() + s.substring(1).toLowerCase(); // Panel
    

    The above will output any input string with the first character in upper case and everything else lower case.

提交回复
热议问题