Reputation: 6442
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
Upvotes: 0
Views: 121
Reputation: 2285
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.
Upvotes: 3