Jump to content

Color the background of cells in a results table.


Recommended Posts

I have this code, and it works perfectly, but when I go to add a 3 option, the colors disappear.

WORKS
<script>document.addEventListener('DataPageReady', function(event) {
        const statusField= document.querySelectorAll('td:nth-child(12)'); // '12' is field number for which styles have to be applied

        statusField.forEach(element => {
            if (element.innerHTML === 'Expires in (30 days)') {
                element.style.cssText = 'background: #FFA200; font-weight: bold; color: #FFFFFF';
            } else if (element.innerHTML === 'Expires in (60 days)') {
                element.style.cssText =  'background: #FBFF00; font-weight: bold; color: #000000';
           }
     
        });

    });
</script>

 

 

DOES WORK Sorry I had a typo I fixed it is now working.

<script>document.addEventListener('DataPageReady', function(event) {
        const statusField= document.querySelectorAll('td:nth-child(12)'); // '12' is field number for which styles have to be applied

        statusField.forEach(element => {
            if (element.innerHTML === 'Expires in (30 days)') {
                element.style.cssText = 'background: #FFA200; font-weight: bold; color: #FFFFFF';
            } else if (element.innerHTML === 'Expires in (60 days)') {
                element.style.cssText =  'background: #FBFF00; font-weight: bold; color: #000000';
           } else if (element.innerHTML === 'Expired') {
                element.style.cssText =  'background: #FF0000; font-weight: bold; color: #FFFFFF';
           }
     
        });

    });
</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...