SharePoint 2013 place holder

SharePoint call javascript after page load with Script Editor WebPart

In SharePoint 2013 they added a Script Editor WebPart. Add this to a page and add the following code in the WebPart Editor.

<SCRIPT LAGUAGE="Javascript">
_spBodyOnLoadFunctionNames.push("color");

function color()
{
var colorCode = document.getElementsByTagName("td");
var i = 0;
for (i = 0; i < colorCode.length; i++) 
{
    if (colorCode[i].className == "ms-cellstyle ms-vb2") 
    {
            if (colorCode[i].innerHTML == "Green") 
        {
                colorCode[i].style.color = 'Green';
            }
            if (colorCode[i].innerHTML == "Yellow") 
            {
                colorCode[i].style.color = 'Yellow';
            } 
            if (colorCode[i].innerHTML == "Red")  
            { 
             colorCode[i].style.color='Red'; 
            }
        } 
}
}
</script>

About the author

Leave a Reply