我的页面上有一个隐藏的div,我只想获取HTML结构。从html()变量中删除所有空格和制表符
<div class="html-to-store visuallyhidden">
<span class="item">
<p>Test</p>
<p>Another Test</p>
</span>
<span class="item">
<p>Second Test</p>
<p>Dadada</p>
</span>
</div>
和我的JavaScript:
var storeThis = $('.html-to-store').html();
现在,这是很好的,但我希望能够得到所有的HTML标签一个单行。
这里的what I'm currently getting:
<span class="item">
<p>Test</p>
<p>Another Test</p>
</span>
<span class="item">
<p>Second Test</p>
<p>Dadada</p>
</span>
我想是这样的:
<span class="item"><p>Test</p><p>Another Test</p></span><span class="item"><p>Second Test</p><p>Dadada</p></span>
如果您有多个类名,这并不好。删除文件夹之间的空间 –
已更新,以防止文件类和文本节点。 – marionebl
很酷,谢谢。这是接受答案的一个很好的选择,如果我关心我的代码的外观,我会采取这种方式,但现在我只想让该死的东西起作用!非常感谢帮助。 –