I'm using a long HTML Template script in JS file, like:
var TEMPLATE = `
<div>
<ul>
<li>first</li>
<li>second</li>
<li>third</li>
</ul>
</div>`;
It works in all browsers(including Chrome, Safari, Firefox & EDGE) but not in Internet Explorer 11, 10.
Can you suggest how I can fix this?
If you look at the ECMAScript 6 compatibility table, you'll see that template literals are not supported by IE11.
ES6 introduces a new kind of string literal syntax called template strings . They look like ordinary strings, except using the backtick character ` rather than the usual quote marks ' or " . In the simplest case, they really are just strings: context.
Backticks are an ES6 feature that allows you to create strings in JavaScript. Although backticks are mostly used for HTML or code embedding purposes, they also act similar to single and double quotes. Besides, using backticks makes it easier for string operations.
If you don't need any of the advanced features available in template literals (such as ${foo}
), you might also consider using regular quotes and just escape the new lines to prevent syntax errors, like so:
var list = '\
<div>\
<ul>\
<li>first</li>\
<li>second</li>\
<li>third</li>\
</ul>\
</div>\
';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With