function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arek S.Arek S. 

Replace text on VisualForce page using JavaScript

I'm working with a VisualForce page (SalesForce related) and I need to write a piece of JavaScript that will replace some text on the page after everything is loaded.

I've tried the following (I'm using jQuery on other parts of the page so I've used jQuery for this also):


var j$ = jQuery.noConflict();
  var replaced = $find("body").html().replace('Test','1234');


Unfortunately it doesn't seem to do anything. It's like I can't get the page HTML code. I'm assuming it's because this is a VisualForce page running on the Force platform, so if anyone can offer any help with this that would be much appreciated.




P.S. In case anyone is wondering why I'm doing this is because I can't do this through VisualForce or Apex since I'm trying to unescape some HTML characters provided by a variable and being used in a dataTable header. Unfortunately everything in a dataTable header is automatically escaped.

Santhosh KumarSanthosh Kumar

Did you test in FF with firebug enabled? It can show if there are any Javascript errors causing nothing to happen. If there are no errors, then may be have you specified the correct selector? 


Instead of selecting whole body, why dont you select particular element you are trying to target and do the manipulation? So browser doesn't have to render whole page again.