I’m trying to make a basic replace code that replaces the match every time.
(function($) {
$.fn.replace = function(obj) {
var a = $(this).html();
for (var i in obj) {
$(this).html(a.replace(i, obj[i]));
}
};
$('#myDiv').replace({
':\)': '<img src="http://bit.ly/dbtoez" />'
});
})(jQuery);
But it doesn’t work. Also, when I put more properties into the object to replace on the div, it doesn’t work. The img element is a smiley face.
Fiddle: http://jsfiddle.net/iambriansreed/kCtLh/
Final Version. It escapes all the characters for you. 🙂