0

So i have pieced together a couple of other peoples code to get it this far but it is having an issue when there are numbers in parts of the html of other elements. What i am trying to do is wrap all numbers on the page in a span. The code i have at the minute:

$(function(){
        $('#page').html(function(i, v) {
                            v = v.text();
            return v.replace(/(\d+)/g, '<span class="caps">$1</span>');
        });
    });

the problem with this though is if i have an image on my page with the file name of something like 'test123.png' it tries to wrap the 123 in a span.

How can i modify this code so that it only uses the text of elements and not the html?

Thanks in advance

haxxxton
  • 6,422
  • 3
  • 27
  • 57
  • 1
    http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – elclanrs Aug 10 '12 at 02:57

1 Answers1

3

This plugin is just what you need

http://benalman.com/projects/jquery-replacetext-plugin/

jQuery replaceText will replace text in specified elements. Note that only text content will be modified, leaving all tags and attributes untouched.

Diego ZoracKy
  • 2,227
  • 15
  • 14