javascript - Replacing spaces between html tags with nbsps -
i want replace spaces between html tags nbsps using pure javascript. html:
<div><span>apple</span> <span>grapes</span></div>
you can see spaces between 2 span nodes. these spaces should replaced  s.
result should be:
<div><span>apple</span><span> </span><span>grapes</span></div>
please me.
try simple logic
var input= "<div><span>apple</span> <span>grapes</span></div>" var output = input.replace( /<\/span>\s*<span>/g, function(match){ return match.replace(/\s/g, " ") } ); console.log( output );
Comments
Post a Comment