Given the code line
var value = $("#text").val();
and value = 9.61, I need to convert 9.61 to 9:61. How can I use the JavaScript replace function here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do it like this:
Updated to reflect to current version of jQuery. And also there are a lot of answers here that would best fit to any same situation as this. You, as a developer, need to know which is which.
Replace all occurrences
To replace multiple characters at a time use some thing like this:
name.replace(/&/g, "-"). Here I am replacing all&chars with-.gmeans “global”Note – you may need to add square brackets to avoid an error –
title.replace(/[+]/g, " ")