I have a large HTML string contained in a var
. I'm using it to write to innerHTML
.
The first example (with backtick syntax), which is the simplest, does not work in Internet Explorer 11.
Is there a way to get the first example to work in Internet Explorer 11 without having to use an array or newline characters?
Does not work in Internet Explorer
Backtick `
https://jsfiddle.net/qLm02vks/
<div id="display"></div>
var message = `
<p>this</p>
<p>is</p>
<p>a</p>
<p>multiline</p>
<p>string</p>
`;
// Write Message
var display = document.getElementById('display');
display.innerHTML = message;
Works in Internet Explorer
Array Join
https://jsfiddle.net/3aytojjf/
var message =
['<p>this</p>',
'<p>is</p>',
'<p>a</p>',
'<p>multiline</p>',
'<p>string</p>'
].join('
');
Works in Internet Explorer
Single quote ' with linebreak
https://jsfiddle.net/5qzLL4j5/
var message =
'<p>this</p>
<p>is</p>
<p>a</p>
<p>multiline</p>
<p>string</p>'
;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…