1

Is there a way I can turn this obnoxiously long line of text into a paragraph?

Before:

$('.ContText-1').text('For a business to thrive, it needs a team of people who are dedicated to its success. Paul Lister, Bryan Jeter, and Bryan Lloyd are committed to being a part of that team for each of their clients.');

After:

$('.ContText-1').text('
             For a business to thrive, it needs a team of people who are dedicated to its 
        success. Paul Lister, Bryan Jeter, and Bryan Lloyd are committed to being a part of 
        that team for each of their clients.
');

If I run the paragraph one I get this error: Uncaught SyntaxError: Invalid or unexpected token
Its referencing to the single quotation mark after the (.

3 Answers3

1

Assuming you're attempting to break the string in your code, not the output, you can use a template literal by delimiting the string with `:

$('.ContText-1').text(`
  For a business to thrive, it needs a team of people who are dedicated to its 
  success. Paul Lister, Bryan Jeter, and Bryan Lloyd are committed to being a part of 
  that team for each of their clients.
`);

Note that this is completely unsupported in any version of IE, although works in every other modern browser - even Edge.

Alternatively you can append each line separately:

$('.ContText-1').text(
  'For a business to thrive, it needs a team of people who are dedicated to its ' + 
  'success. Paul Lister, Bryan Jeter, and Bryan Lloyd are committed to being a part of ' + 
  'that team for each of their clients.'
);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
0

instead of text() method use html() method and use <br/> to break the line

$('.ContText-1').html('<br/>For a business to thrive, it needs a team of people who are dedicated to its <br/>success. Paul Lister, Bryan Jeter, and Bryan Lloyd are committed to being a part of <br/> that team for each of their clients.');
RAUSHAN KUMAR
  • 5,846
  • 4
  • 34
  • 70
  • The problem isnt the paragraph. The problem is in the code editor I have a long line of code that looks ugly. –  Jun 05 '17 at 13:17
0

Instead of enclosing the String with ' , try to use ` .

At least in newer iteration of JS this should work fine.

UPDATE:

Actually, this had been covered before: Creating multiline strings in JavaScript

Stefan Dochow
  • 1,454
  • 1
  • 10
  • 11
  • That doesnt work because I have single quotation markes in the string and `\` doesnt escape it with ` –  Jun 05 '17 at 13:24