2014-03-30 58 views
0

刪除註釋行後,我的格式化輸出非常糟糕。刪除即時換行

我想刪除剩下的換行符。

HTML

<html> 




<div class="donottouch"> 
</div> 


</html> 

我想這成爲

通緝輸出

<html> 
<div class="donottouch"> 
</div> 
</html> 

沒有進入其他的div。

代碼我用它來刪除註釋行:

$('> *', $content).contents().each(function() { 
    if (this.nodeType == 8) { 
     $(this).remove() 
    } 
}); 

非常感謝你提前!

最好的問候,

亞歷

+1

爲什麼你想這樣做?你真的沒有獲得/失去任何東西...... – nietonfir

回答

0

你可能想看看jQuery.trim() utilitiy:

說明:

從一開始和結束時刪除空格一個字符串。 $ .trim()函數從提供的字符串的開始和結尾刪除所有換行符,空格(包括非中斷空格)和製表符。如果這些空白字符出現在字符串中間,它們將被保留。

例子:

開始和在字符串的結尾處刪除空格:
$.trim(" hello, how are you? ");

結果:
"hello, how are you?"