Hamid Reza
Hamid Reza

Reputation: 2973

How to concat special characters as sting to a text in javascript?

How to concat character \ as a string to a text in javascript? I want to write this code line in javascript:

var x = "$$\" + $("#formul").val() + "$$";

How to do this?

Upvotes: 1

Views: 5340

Answers (1)

James Allardice
James Allardice

Reputation: 166021

Escape the backslash:

var x = "$$\\" + $("#formul").val() + "$$";

The problem you have currently is that the backslash is the escape character. It escapes the following " character so your string doesn't close.

Upvotes: 5

Related Questions