jQuery
jQuery Replace Dot Or Period Examples
Ever wanted to replace Dot or Period using jQuery? In this article, I am going to show you how to easily replace a dot or a period with any other character using jQuery.
Examples on using jQuery to Replace Dot
Let’s assume that you have a div with ID “my_div” and you would like the dot to be replaced by another character using jQuery and assign the new text back to the same div. Here’s how you can do it.
Example 1: Replace all Dots / Periods in a Div with Space using jQuery:
$(document).ready(function() {
var str = $("#my_div").html().replace(/\./g, ' ');
$("#my_div").html(str);
});Example 2: Replace all Dots / Periods in a Div with Dash using jQuery:
$(document).ready(function() {
var str = $("#my_div").html().replace(/\./g, '-');
$("#my_div").html(str);
});Example 3: Replace all Dots / Periods in a Div with multiple dashes using jQuery:
$(document).ready(function() {
var str = $("#my_div").html().replace(/\./g, '---');
$("#my_div").html(str);
});Example 4: Remove all Dots / Periods in a Div using jQuery:
$(document).ready(function() {
var str = $("#my_div").html().replace(/\./g, '');
$("#my_div").html(str);
});Example 5: Remove all Dots / Periods in the entire body of the HTML page using jQuery:
$(document).ready(function() {
var str = $("body").html().replace(/\./g, '');
$("body").html(str);
});That’s it!
Do you know of any other ways to use jQuery to replace dot / period? Feel free to suggest by commenting below.