342 posts
  • Affiliate Level 4
  • Author Level 5
  • Beta Tester
  • Collector Level 3
+6 more
vtimbuc
says

Hey guys I’m working on a new project and I need to send some text via jQuery to a pre tag.

Here is what I want to achieve:

I have this jQuery to add this text to a “pre” tag.

$('pre').text('Line 1, Line 2, Line 3, Line 4, Line 5');

But I don’t know how can I add this text via jquery to be formatted this way without using <br> tags

<pre>
Line 1,
Line 2,
Line 3,
Line 4,
Line 5
</pre>

Is possible to do that?

287 posts
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • Elite Author
+12 more
DPereyra
says

Try this:

$('pre').text('Line 1, \n\rLine 2, \n\rLine 3, \n\rLine 4, \n\rLine 5'); http://jsfiddle.net/t5VZL/
342 posts
  • Affiliate Level 4
  • Author Level 5
  • Beta Tester
  • Collector Level 3
+6 more
vtimbuc
says

That will work, thank you DPereyra :)

342 posts
  • Affiliate Level 4
  • Author Level 5
  • Beta Tester
  • Collector Level 3
+6 more
vtimbuc
says

When I tested it on my project it didn’t worked. I’ve got an “Unexpected token Illegal”..

287 posts
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • Elite Author
+12 more
DPereyra
says

Hi,

Are you sure that you copied the code correctly?

342 posts
  • Affiliate Level 4
  • Author Level 5
  • Beta Tester
  • Collector Level 3
+6 more
vtimbuc
says

Yes, maybe it only works on a server.

342 posts
  • Affiliate Level 4
  • Author Level 5
  • Beta Tester
  • Collector Level 3
+6 more
vtimbuc
says

If I copy it from jsfiddle it doesn’t work, had to type it on the document. It’s working now, thanks.

by
by
by
by
by
by