The .replace() method does change the string in place

replace() (a JavaScript function, not jQuery) returns a string, try this :

var valr="r";
valr = valr.replace('r', 't');
$('.try').prepend('<div> '+valr+'</div>');

Docs for .replace() are here

Leave a Comment