I want to replace spaces between html tags with nbsps using pure JavaScript. This is my html:
<div><span>Apple</span> <span>Grapes</span></div>
You can see spaces between 2 span nodes. These spaces should be replaced by  s.
Result should be:
<div><span>Apple</span><span> </span><span>Grapes</span></div>
Please help me.
Try this 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 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.