TD background coloring

Isaac
Isaac used Ask the Experts™
on
When I use the following code to set the background column based on a status, it works perfectly but it hides the "List Tools" tab on the ribbon, which prevents me from getting to the different settings for the list.

Any ideas why that's happening?

Thanks!


<script type="text/javascript" language="javascript"> 
  var x = document.getElementsByTagName("TD") // find all of the TDs 
  var i=0; 
  for (i=0;i<x.length;i++) 
  { 

    if (x[i].className=="ms-vb2") //find the TDs styled for lists 
    {
     if (x[i].innerHTML=="CLOSED") //find the data to use to determine the color 
  { 
    x[i].style.backgroundColor='darkblue'; // set the background color 
    x[i].style.color='white'; //set the font color 
  }
          //repeat the above for each data value 

      if (x[i].innerHTML=="OPEN") //find the data to use to determine the color 
  { 
    x[i].style.backgroundColor='darkgreen'; // set the background color 
    x[i].style.color='white'; //set the font color 
  }
    } 

  } 
</script> 

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Cloud Expert
Most Valuable Expert 2013
Top Expert 2014
Commented:
I don't know why but I'd have done it a different way. We have these cool XSLT List Views available now, if you have SharePoint Designer you can introduce conditional formatting, including changing the colour based on value as you're doing.

Randy Drisgall did a lab on this in his branding book, which is on Google Books here (page 88);

http://books.google.ch/books?id=NXg0DqrAEIAC&pg=PA303&lpg=PA303&dq=sharepoint+XSLT+List+View+Web+Part+conditional&source=bl&ots=tiKcTeaMpr&sig=yZlnRCW0W15kPdp5Zs0NVhvCC5E&hl=en&sa=X&ei=luOOT5nIFsOFhQelttD-Cg&ved=0CFYQ6AEwBw#v=onepage&q=sharepoint%20XSLT%20List%20View%20Web%20Part%20conditional&f=false

I suggest you do it that way. More powerful. Cleaner. Handled from the SharePoint end.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial