Jasper
Jasper

Reputation: 161

Add quotation marks to variable

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?

Upvotes: 0

Views: 193

Answers (1)

SoroushNeshat
SoroushNeshat

Reputation: 674

try this :

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

Upvotes: 1

Related Questions