333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 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
  • Elite Author: Sold more than $75,000 on Envato Market
  • Won a competition
  • Has sold $125,000+ on Envato Market
  • Has referred 100+ members
+9 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/
333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

That will work, thank you DPereyra :)

333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

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

287 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Won a competition
  • Has sold $125,000+ on Envato Market
  • Has referred 100+ members
+9 more
DPereyra says

Hi,

Are you sure that you copied the code correctly?

333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

Yes, maybe it only works on a server.

333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 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