开发者

Is this an efficient way to convert HTML to text using jQuery?

I'm trying to convert HTML to plain text. Is it efficient? Am I missing something?

txt = $("body").find("script,noscript,style,:hidden").remove().end开发者_JAVA百科().text();

Thanks!


HTML is text.

EDIT Try this...

// Get current body text
var html = $("body").text();

// Create a new jQuery object out of body text and remove desired elements
var text = $(html).remove("script,noscript,style,:hidden").text();


You want element.textContent (element.innerText for IE).


var scriptContents = $('body').find('script').html();
var noScriptContents = $('body').find('noscript').html();
var styleContents = $('body').find('style').html();


If you're trying to just render it to the screen you might be able to:

<pre>
    some html here
</pre>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜