Search code examples
javascripthtmlcarriage-returnprelinefeed

How are <pre> whitespace and line return "saved"?


If you want to toy with white-spaces, tabs, linefeed and carriage-return, how do you "select them" in javascript?

  x = $('pre').html().replace(/(\r\n|\n|\r)/gm, "#");

edit : ^Does not work for linefeed and carriage-return.

Now, tabs are /(\t)/ and spaces are /( )/.


Solution

  • Your example actually works.

    http://jsfiddle.net/RSfN5/1/