Reputation: 37
I am trying to pass the following content into a jquery variable but when I click on it it says expected expression, got }. It has to do with the quotation right? How am I supposed to use double and single quotes in this instance?
var content = $("<div class='channel' id='general' onclick='jumpToFirstLevelRoom('general')'>General</div>")
Upvotes: 0
Views: 958
Reputation:
I got the problem in your code. The problem is in that statement where you are calling a function and passing arguments.
var content = $("<div class='channel' id='general' onclick='jumpToFirstLevelRoom('general')'>General</div>")
You are passing a string general in function jumpToFirstLevelRoom('general'). So when you are starting single quotes of string general, It is behaving as closing quote of onclick=' .
Try to not pass the string in the function as argument. Then the code will run. I hope it will help you. :)
Upvotes: 0
Reputation:
What you are looking for is this:
var content = $("<div class='channel' id='general' enter code hereonclick='jumpToFirstLevelRoom(\'general\')'>General</div>");
You need to use escape characters to remove double quotes.
Upvotes: 0
Reputation: 12181
Change your current code
var content = $("<div class='channel' id='general' onclick='jumpToFirstLevelRoom('general')'>General</div>")
to
var content = $("<div class='channel' id='general' onclick='jumpToFirstLevelRoom(\'general\')'>General</div>");
Just use escape
characters
.
With es6 you can do
var content = $(`<div class='channel' id='general' onclick='jumpToFirstLevelRoom("general")'>General</div>`);
Hope this will solve the problem.
Upvotes: 0
Reputation: 415
Yes your quotes are wrong. You have unescaped single quotes inside single quotes.
You should use either of these quotation techniques :
Different quotes :
var content = $("<div class='channel' id='general' onclick='jumpToFirstLevelRoom(`general`)'>General</div>")
Escaped quotes :
var content = $("<div class='channel' id='general' onclick='jumpToFirstLevelRoom(\'general\')'>General</div>")
Upvotes: 4
Reputation: 346
You can use the escape sequence to remove the double quot from the variable.
var content = $("<div class=\"channel\" id=\"general\" onclick=\"jumpToFirstLevelRoom('general')\">General</div>")
Upvotes: 0