I am writing some jquery script that will run across a large amount of completely different web pages (different domains too) and it will surround certain words on the page with html tags to style them up - make them more noticeable etc. Here's some sample code I've written...
$('body').ready(function() {
var body = $('body').html();
var matches = body.html().match(/a complex regular expression here which matches a variety of things/g);
var match;
for (var i=0; i<matches.length; i++)
{
match = matches.pop(); // go through each matched instance
body = body.replace(match,"<h1>"+match+"</h1>"); // style each matched instance in the document body
}
$('body').html(body); // set it back onto document body
});
The problem is, certain domains on which this script is to be run on - on 'body'.ready they only load very basic stuff and load nearly all their content afterwards using ajax/javascript.
So at line 2 of my code where I retrieve the body's html it only contains the bare bones for some of these webpages at this time therefore later when the matched instances are replaced and put onto the DOM the changes are made but on a page which was only half-loaded.
I hope this makes sense. If you know a workaround for this then please share.