使用jquery从元素之间删除不间断空格(& nbsp;)
问题描述:
如何使用jquery删除html元素之间出现的不间断空格(nbsp)?
How can I use jquery to remove non-breaking spaces (nbsp) which appear between html elements?
因此,例如,以下代码是由cms生成的:
So, for example, the following code is generated by a cms:
<div><span>content</span> <span>content</span></div>
我能够使用弹子瞄准目标.
I am able to target the elements using slectors.
下一页提出了删除正常空格而不删除不间断空格的答案. 使用jQuery删除HTML元素之间的空格和换行符
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
谢谢
答
var div = "<div><span>content</span> <span>content</span></div>";
var newdiv = div.replace(/ /g,'');