Multiple lines when using jQuery's .html method

use \ to escape new line chars.

$("#someID").html("\
    <h1>Headline 1</h1>\
    <h1>Headline 2</h1>\
    ");

View working example here: http://jsfiddle.net/amantur/yeDff/


You could use string concatenation to join the new lines. Its clean too.

$("#someID").html("" +
    "<h1>Headline 1</h1>" +
    "<h1>Headline 2</h1>");

It's a bit late but now can do even cleaner:

$("#someID").html(`
    <h1>Headline 1</h1>
    <h1>Headline 2</h1>
    `);

And you can even add variables without concatenation:

$("#someID").html(`
    <h1>${headline1}</h1>
    <h1>${headline2}</h1>
    `);

Tags:

Jquery