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 &nbsps.

result should be:

   <div><span>apple</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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, "&nbsp;") } );    console.log( output );


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -