319 posts
  • Sold between 10 000 and 50 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Exclusive Author
  • Portugal
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?

281 posts
  • Elite Author
  • Won a Competition
  • Argentina
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
+3 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/
319 posts
  • Sold between 10 000 and 50 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Exclusive Author
  • Portugal
vtimbuc says

That will work, thank you DPereyra :)

319 posts
  • Sold between 10 000 and 50 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Exclusive Author
  • Portugal
vtimbuc says

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

281 posts
  • Elite Author
  • Won a Competition
  • Argentina
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
+3 more
DPereyra says

Hi,

Are you sure that you copied the code correctly?

319 posts
  • Sold between 10 000 and 50 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Exclusive Author
  • Portugal
vtimbuc says

Yes, maybe it only works on a server.

319 posts
  • Sold between 10 000 and 50 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Exclusive Author
  • Portugal
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