jQuery Replace part of string using a variable
jquery, replace
Solution
You need to save the replaced string
var url = "At vero eos et accusam et justo duo dolores et ea rebum.";
url = url.replace('At vero eos et accusam et ', '');
//^^^^^this
DEMO
Problem
This one seems simple, but I have no idea why it's not working. I would like to replace part of a string in a variable. Say, I have this code: ``` var url = "At vero eos et accusam et justo duo dolores et ea rebum."; url.replace('At vero eos et accusam et ', ''); ``` Why doesn't it work? This one works: ``` var url = "At vero eos et accusam et justo duo dolores et ea rebum.".replace('At vero eos et accusam et ', ''): ``` -- but I'm using the variable elsewhere, so I would like to keep the replace out of the variable definition. Fiddle here.