SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My goal is to replace a text in a specific column by an icon using only javascript.

function ReplaceTxtbyIcn(targetWP, targetColumn, pat, urlname)
  var table = document.getElementById(targetWP);
  if (table != null)
      var tbody = table.childNodes[0];
      var trs = tbody.childNodes;
      for (var i=1;i<trs.length;i++)
        var tdVal = trs[i].childNodes[targetColumn].outerText;
        if( tdVal == pat)
         $(trs[i].childNodes[targetColumn]).append('<img src="******SomeURL******'+urlname+'.png"  alt="'+pat+'"/>');

For targetWP it should be equal to ctx.listName + "-" + ctx.view My problem here is how to get the ctx for the specific webpart using the id of the webpart. I am on Sharepoint 2007, any help ?

share|improve this question
up vote 0 down vote accepted

The following function could be used for retrieving Context Info by Web Part ID

//Retrieve Context Info By WebPartID
function getContextInfo(webPartID)
        //Resolve ViewId from WebPartId
        var strViewId=webPartID.toUpperCase();
        //Retrieve Context Info Number
        var ctxNum=g_ViewIdToViewCounterMap[strViewId]; 
        if (ctxNum==null)
            return null;
        //Retrieve Client Context by Number  
        var ctxT=window["ctx"+ctxNum];
        return ctxT;


//Retrieve Context Info for Latest Documents Web Part 
function loadLatestDocumentsContextInfo()
    var curctx = getContextInfo('{d8e2098c-170d-4114-92f1-95619f716911}');


Note: Web Part ID could be identified on page as specified here

share|improve this answer
Tested with SharePoint 2010 only – Vadim Gremyachev Jan 2 '13 at 21:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.