Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 5

Javascript backticks causing error in IE11?

Hello,

I'm working on a personal page with very limited knowledge of html so I apologize for the simplicity of my question.

The following javascript is causing errors only in IE.

$("#mouseXY").html(`X: ${mouse.x*10} Y: ${mouse.y*10}`);

Searching through google has led me to believe that it's the ` symbols that are causing this issue in IE as it doesn't support template literals? The script runs perfectly fine on every other browser.

How can I alter this portion of the script to make it work for IE?

I've tried everything I can with my little knowledge of html with no success..

Any help would be greatly appreciated.

Thank you.

2 Answers

Relevance
  • Chris
    Lv 7
    4 years ago
    Favorite Answer

    Correct, IE11 doesn't support all of ES6's features.

    The well-supported way of including variables into text is adding it:

    $("#mouseXY").html("X: " + (mouse.x*10) + " Y: " + (mouse.y*10));

    Or use this slightly more readable version:

    var x = mouse.x * 10;

    var y = mouse.y * 10;

    $("#mouseXY").html("X: " + x + " Y: " + y);

  • 4 years ago

    htg

Still have questions? Get your answers by asking now.