Search code examples
javascriptcsssharepointsharepoint-2010sharepoint-2013

Change color text of specific text in sharepoint


I was doing some testing(issue tracking) and I initiated a workflow, a 3 state workflow. The workflow is shown as completed or in progress. Can I change the color of the words? For example, in progress would be orange and completed would be in green.

Please Advise.

For Reference: https://i.sstatic.net/PX1xx.jpg


Solution

  • In SharePoint 2013, we can add the following code into a script editor web part to achieve it.

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() { 
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
            OnPostRender: function (ctx) {
                $("td.ms-vb2>a>span").each(function(){
                    if($(this).text()=="In Progress"){
                        $(this).css("color","orange");
                    }
                    if($(this).text()=="Completed"){
                        $(this).css("color","green");
                    }
                });
                $("td.ms-vb2").each(function(){
                    if($(this).text()=="Closed"){
                        $(this).css("color","red");
                    }
                    if($(this).text()=="Active"){
                        $(this).css("color","green");
                    }
                });
            }
        });
    });
    </script>
    

    enter image description here