Hey, One component to my current project involves retrieving various blocks of text and html from a database that are displayed on a website (a website that is composed of the same blocks of text and html from the same database) via $.getJSON, and thereafter locating each of the retrieved blocks on the page and wrapping them with some sort of tag.
Normally I would do this through PHP, simply inserting the tags around each of the variables that contained information from the database however under the particular limitations for my project, I am unable to do so. Currently I am using soemthing similar to this: $.getJSON('json.scriptage.php' function(data) { for(var i=0,imax=data.length;i<imax;i++) { var shtml = data[i]; var rx = new RegExp('/^ '+shtml+' $/'); $(":contains('"+shtml+"'):last").each(function(){ $(this).html($(this).html().replace(rx, '<ttt>'+shtml+'</ttt>')); }); } }); My thoughts that my for loop should cycle through the decoded JSON array (i.e. all of the values retrieved from the database), find the lowest-level container of the value's html, and use a replace function on said html to wrap it with the new tags. My problems with my current system are twofold: -The first is that the :contains selector only accounts for elements that contain the text passed as an argument, and does not seem to account for html. -The second is simply that I cannot seem to make it work for text, as things stand. I'm not quite sure where my error is here, but not even in the instances where the values retrieved from the database are pure text will this code properly replace the occurrences on the page. Any modifications to my code or suggestions are very much appreciated! I'd imagine there's some method of completing this task that is a thousand times easier that I'm overlooking. Thanks ~KuroTsuto