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,'-');

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.

Responsive Menu
Add more content here...