tags:

views:

33

answers:

3

I have a large html string that I am populating with data and using in an innerHTML...

I want to make a string like this:

var str = '<div>
    <div></div>
    </div>';

Instead of like this:

var str = '<div>'
    +'<div></div>'
    +'</div>';

Is there a way?

+4  A: 

A backslash at the end of the line will indicate that the line is continuing to the next:

var str = '<div>\
    <div></div>\
    </div>';
JacobM
This works thanks.
John Isaacks
Make sure there's no whitespace after the slash. That'll getcha every time.
InfinitiesLoop
+1  A: 

While probably not what you are looking for, you can also do something like this:

var str=[];
str.push('<div>');
str.push('<div></div>');
str.push('</div>');
html = str.join('');
michael
+1  A: 

You can use a backslash..

var str = 'bla\
   foo\
    bar';

You can join it:

var str = ['foo',
'bar',
'baz'].join('')

You can push and then join it:

var a = [];
a.push('<div>');
a.push('blah');
a.join('')
meder