0

In a list of footnote references for an article, I want to select all occurences of "(en)" and wrap them in some so that I can apply bold style to them as well as a right margin.

How to do that with jQuery ?

Eli
  • 14,779
  • 5
  • 59
  • 77
drake035
  • 3,955
  • 41
  • 119
  • 229
  • 1
    Can you show us some relevant html? Otherwise we have to assume it's 1 container with some text in it, but the answer is completely different if that's not the case. – Reinstate Monica Cellio Oct 10 '12 at 13:30

2 Answers2

2

lets say you can get all your data into a string:

var myString = $('#footnotes').html();

Since you don't need regex you can split into an array and rejoin.. ex:

var newString = myString.split("(en)").join("<span class='en-element'>(en)</span>");
$('#footnotes').html(newString);
Reinstate Monica Cellio
  • 25,975
  • 6
  • 51
  • 67
James L.
  • 4,032
  • 1
  • 15
  • 15
1

Using regex to find the "(en)"'s, and then using string.replace to replace them with the content you want.

I know when to use regex but am not too familiar with it's sintaxys, so sorry for not providing the exact code, take a look at this post in which they tried to do the same but finding
and replacing it with \n

jQuery javascript regex Replace <br> with \n

Community
  • 1
  • 1
aleation
  • 4,796
  • 1
  • 21
  • 35