Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCRIPT1014: Invalid character - Quote symbol

I have this problem:

array[i].idAuthor is a String variable. I want to pass this String to a function which is called inside an append-String.

The code works fine in Chrome and Firefox except for Internet Explorer. IE gives me this error: SCRIPT1014: Invalid character

I think the issue are the `-Quotes.

I hope the following example helps to express my problem.

<script>
(...)
    $("#id").append("<div onClick='myFunc(`" + array[i].idAuthor + "`);'>" + i + "</div>");
(...)
<script>

Is there another way to handle my situation or to replace the `-Quotes with another character that is compatible with IE?

like image 251
clyx Avatar asked Dec 10 '22 16:12

clyx


1 Answers

It looks like you're putting backticks (`) into your string there.

onClick='myFunc(`" + ... + "`);'>

In modern browsers, backticks are used for template literals. IE11 doesn't support template literals.

Instead, try escaping your quotes:

onClick='myFunc(\"" + array[i].idAuthor + "\");'>
like image 104
Mike Cluck Avatar answered Dec 25 '22 18:12

Mike Cluck