Question: How can I transform the string "Test(5)" into "Test\(5\)" dynamically? (JQuery or Javascript)

I have tried this but with no success

```
var string = "Test(5)";

string = string.replace("(","\(");
string = string.replace(")","\)");

console.log(string);

```

<http://jsfiddle.net/mvehkkfe/>

Answer: 
I assume you meant

> 
> replace the string "Test(5)" into "Test\(5\)"
> 
> 
> 

In which case:

```
var string = "Test(5)";

string = string.replace("(","\\(");
string = string.replace(")","\\)");

console.log(string);

```

Escape the backslash
If you want to replace the string "Test(5)" into "Test\(5\)", you can use below code

```
var string = "Test(5)";

string = string.replace("(","\\(");
string = string.replace(")","\\)");

console.log(string);

```