Skip to content

Instantly share code, notes, and snippets.

@mukunda-
Created September 13, 2014 06:58
Show Gist options
  • Save mukunda-/ffa824bbba5d7f572a77 to your computer and use it in GitHub Desktop.
Save mukunda-/ffa824bbba5d7f572a77 to your computer and use it in GitHub Desktop.
Read element text with converted line breaks
// read element text with converted line breaks
function readText( element ) {
// invisible "workspace" element
mb = $('#magicbox');
// copy over the html, with replaced <br> tags
var content = $(element).html();
content = content.replace( /<br>/g, '[[br]]' );
mb.html( content );
// return the element text, letting whatever convert
// the rest of the html data to text
return mb.text().trim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment