How to merge the same span tags into one tag

How Can We Help?

< Back
You are here:
Print

If your HTML has the same span tags in a row like in the code sample below and you would like to have just one span tag then you can use custom JavaScript code that will fix your HTML.

<p>
   <span lang="en">This is span</span> <span lang="en">This is span 2</span>
</p>
<p>
   <span style="font-size: 12px">This is span</span>
   <span style="font-size: 12px">This is span 2</span>
   <span style="font-size: 12px">This is span 3</span>
</p>

Please try the following custom JavaScript code that will process your HTML span tags:

var htmlLength = 0;
while (htmlLength != html.length )
{
   htmlLength = html.length;
   html = html.replace(/(<span[^<>]*>)([\s\S]*?)(<\/span>)(\s*)\1([\s\S]*?)\3/gi, "$1$2$4$5$3");
}

Just copy and paste it into Custom JavaScript editor and click Cleanup HTML green button under HTML editor.

After you click Cleanup HTML button all the same span tags will be merged into one <span..> tag like below:

<p>
   <span lang="en">This is span This is span 2</span>
</p> 
<p>
   <span style="font-size: 12px">This is span This is span 2 This is span 3</span>
</p>