0

I'm struggling with something in JQuery and I don't get it. I'm trying to add quotation marks to a variable in a parameter for a function.

$(".menu").append("<div class='language' onclick='changeLanguage("+ input.translation +");'>Change language</div>");

The onclick-output has to be something like changeLanguage('en') and not changeLanguage(en), where "en" is a string and not a variabele. But everything I'm trying ends in an error.

What I am doing wrong? In which way to I have to add the quotation marks to get it work?

Jasper
  • 139
  • 1
  • 7
  • Possible duplicate of [Put quotes around a variable string in JavaScript](https://stackoverflow.com/questions/9714759/put-quotes-around-a-variable-string-in-javascript) – Ashraf Jul 29 '18 at 09:00

1 Answers1

1

try this :

$(".menu").append("<div class='language' onclick='changeLanguage(\""+ input.translation +"\");'>Change language</div>");
SoroushNeshat
  • 656
  • 5
  • 11