jQuery Replace Strings

Below is simple jQuery code snippets to replace all the dots (.) present on HTML page and then replace it with hyphen.

Earlier I had posted about jQuery solution to substring, split string, trim string and about all string functions, And In this post, see jQuery/JavaScript replace function in action with example.

$(document).ready(function() {
    var strNewString = $('body').html().replace(/\./g,'-');
    $('body').html(strNewString);
});
Remember: Replace functions returns a string which contains the updated text. So you need to first assign into a variable and then re-assign it.

Instead of, (.) or "-", text can be anything. All you need is to make change in the replace function arguments and you are good to go.
See live Demo and Code.
Feel free to contact me for any help related to jQuery, I will gladly help you.
SHARE

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..