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().text();
Thanks!
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().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();
If you're trying to just render it to the screen you might be able to:
<pre>
some html here
</pre>
var scriptContents = $('body').find('script').html();
var noScriptContents = $('body').find('noscript').html();
var styleContents = $('body').find('style').html();