JavaScript does not allow characters to break literal lines within strings.
There are several ways to work around the problem.
If you really want line breaks within the string, use \n
:
$( '.qualquerClasse' ).html( 'conteúdo de 3 linhas de código: uma \n Duas \n Três' );
Note however that line break characters within HTML by default are not rendered (collapsed spaces) unless they are within an element whose computed value of the CSS property
white-space
is
pre
/
pre-wrap
/% with%. Otherwise (in most cases) you must use
pre-line
to force a visible line break.
If you want to break the text into several lines to make it more readable, you can concatenate or use an array:
$( '.qualquerClasse' ).html(
' conteúdo de 3 linhas de código: uma'
+ 'Duas'
+ 'Três'
);
//ou
$( '.qualquerClasse' ).html([
' conteúdo de 3 linhas de código: uma',
'Duas',
'Três'
].join(''));
Of course you can add <br>
or \n
as needed in these strings.
There is also a non-standard way of "escaping" the line break by putting a <br>
just before the literal break:
$( '.qualquerClasse' ).html( ' conteúdo de 3 linhas de código: uma\
Duas\
Três'
);
This syntax is not standard, but it has very good support. However, some browsers keep the line break characters within the string while others discard them, so this form is somewhat inconsistent. Another problem is that adding any character after \
, even a space character, will generate a syntax error since the line break is no longer escaping.