$(".phone_number").html(function(index, text) { return text.replace(new RegExp("xxxx", 'g'), "<span class='phone_number_xxxx'>xxxx</span>") });