开发者

Capture text including line breaks, whitespace from DOM in jQuery?

Suppose I have the following HTML on the page:

<div id="Test">
One
Two
</div>

and this jQuery:

var contents=$("div#Test").html()

In Chrome and Firefox, the resulting string contents includes line breaks - that is, between "One" and "Two" there's character code 10. In IE, though, it seems to collapse any white space and line feeds to a single space (character code 32).

I want to take contents and pass it to a Markdown engine, so 开发者_运维百科I need the whitespace and linefeeds to come through as is. How can I do this?


Try this:

var contents = $(div#Test).clone();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜