Remove every white space between tags using JavaScript

前端 未结 5 1593
你的背包
你的背包 2020-12-30 06:57

I\'m trying to remove white space between tags so that childNodes only contain those tags nodes not the white space nodes too. Here\'s my code :

  • 5条回答
    •  死守一世寂寞
      2020-12-30 07:21

      only spaces:

      parentHTML = parentHTML.replace( new RegExp( "\>[ ]+\<" , "g" ) , "><" ); 
      

      new line, tabs and spaces:

      parentHTML = parentHTML.replace( new RegExp( "\>[\s]+\<" , "g" ) , "><" ); 
      

      https://regex101.com/r/sD7cT8/1

    提交回复
    热议问题