Using javascript, I need to parse the HTML of a page and replace all occurrences of ABC with ABC that occur within a content block such as <p>ABC Company lorem ipsum</p> would be changed to <p><span class="abc">ABC</span> Company lorem ipsum</p> but mailto:[email protected] would stay the same.
So pretty much replace ABC anywhere that is preceded by a space or quote, but obviously I would like to make it a little more generic. Perhaps the expression would say when it is not preceded/followed by [a-zA-z].
What I have so far:
<script type="text/javascript">
$(document).ready(function() {
$('body').find('div').each(function(i, v) {
h = $(v).html();
if (h.indexOf('abc') > 0) {
h = h.replace('abc', '<span class="abc">abc</span>');
$(v).html(h);
}
});
});
</script>
<div><div>abc</div></div>to become<div><div><span class="<span class="abc">abc</span>">abc</span></div></div>