How to insert multi-line html code into js?
-
I insert with Jquery my html code
$('div').append('<div>text<div>text2</div></div>');
But it is very difficult to read the code when there is a lot of it and it is stuffed into one line. Is it possible to format it somehow conveniently?
var test = /* <div> text <div> text2 </div> </div> */; $('div').append(test);
JavaScript Isabelle Hickman, Dec 7, 2020 -
`<div>
text
<div>
text2
</div>
</div>`Harper Woods -
I usually do this:
var test = '<div>'+
'text'+
'<div>'+
'text2'+
'</div>'+
'</div>';
$('div').append(test);
An example with more complex markup:
P. S. I didn't know that, but it turns out you can use `as quotes, this is probably the best option:
var test = `
<div>
text
<div>
text2
</div>
</div>
`;
$('div').append(test);Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!