简体   繁体   English

原始JavaScript删除元素周围的一些空格

[英]Raw JavaScript to remove some spaces around an element

Can anybody help with finding a raw JavaScript solution to remove some spaces around an anchor element. 任何人都可以帮助寻找原始的JavaScript解决方案来删除锚元素周围的一些空格。

I currently have the anchor nested in a table cell and there's an   我目前在表格单元格中嵌套了锚点,并且有一个  just before the anchor that causing the anchor (which I've styled to be a block element) to appear on the next line. 就在锚点之前,导致锚点(我将其设置为块元素)出现在下一行。

I'm pretty sure I know how to do it with jQuery but I wanted a raw JavaScript solution, can anybody help? 我很确定我知道如何使用jQuery,但是我想要一个原始的JavaScript解决方案,有人可以帮忙吗?

Example . 例子

This code removes &ampnbsp; 此代码删除了&ampnbsp; before anchor: 锚定之前:

var s = document.getElementById('ttt').innerHTML;
s = s.replace(/&nbsp;[\s\r\n\t]*(<a)/gm, "$1");
document.getElementById('ttt').innerHTML = s;

"ttt" - your table id attribute. “ ttt”-您的表格ID属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM