Remove non breaking space ( ) from between el

2019-02-21 02:24发布

How can I use jquery to remove non-breaking spaces (nbsp) which appear between html elements?

So, for example, the following code is generated by a cms:

<div><span>content</span>&nbsp;<span>content</span></div>

I am able to target the elements using slectors.

The following page suggests an answer to remove normal whitespace, but not non-breaking spaces. Remove whitespace and line breaks between HTML elements using jQuery

Thanks

1条回答
我只想做你的唯一
2楼-- · 2019-02-21 02:58
var div = "<div><span>content</span>&nbsp;<span>content</span></div>";    
var newdiv = div.replace(/&nbsp;/g,'');

demo

查看更多
登录 后发表回答