0

Is there a way I can change the basic text version of '&' and replace it with an image? I was thinking can we do it in jQuery? I don't want to use php for this.

Or is there a way to target it using css?

Thanks.

Naota
  • 668
  • 2
  • 12
  • 17
  • can you explain more ? i didn't get what you want? – kobe Jul 05 '11 at 05:39
  • @kobe - I want to swap the text version of an ampersand with an image or a font-face, to make it look prettier. An auto replace method would be useful for automation sites like blogging. A force. – Naota Jul 05 '11 at 05:45
  • ok got it now , thanks for providing more info – kobe Jul 05 '11 at 05:47

2 Answers2

2

Yes, you could do it like this (asuming you want to replace inside #container element):

var origText = $("#container").text();
$("#container").text(origText.replace(/&/g, "__img_mark__"));
var intermediateHtml = $("#container").html();
$("#container").html(intermediateHtml.replace(/__img_mark__/g, '<img src="ampersand.gif" />'));

We're doing it in 2 steps because we don't want ampersands in the html code to be replaced

Hope this helps. Cheers

Edgar Villegas Alvarado
  • 18,204
  • 2
  • 42
  • 61
  • @Edgar I don't quite get why you need to do this in two steps, if you don't mind, can you explain it to me please? –  Jul 05 '11 at 06:39
0

You could probably search for & or &amp; and use the String.replace method to replace it with your image.

  • Ok, whoever upvoted, thanks. I still don't get why this got downvoted :/ –  Jul 05 '11 at 06:05