This code shows you that how you can replace some part of string or whole string with your new string using javascript function on button click event.