I used the above code to apply a background color on a line with the word High in a field (choice). It does not work. I have used a code that matches exactly the word as in other fields (descriptions etc) there might be written the word High in other contexts.

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

<script type="text/javascript">

    $("td .ms-vb2").filter( function (index) {

       return $(this).text() == "High";

$Text.parent().css("background-color", "#F5A9A9");


What am I doing wrong?


1 Answer 1


The filter() method creates a new array with all elements that pass the test implemented by the provided function.

Instead you can try this (Applies to classic List Views only):

<script type="text/javascript">

    $("td.ms-vb2").each( function () {

       if($(this).text() == "High"){
       $(this).parent("tr").css("background-color", "#F5A9A9");
       //$(this).closest("tr").css("background-color", "#F5A9A9");


  • I was able to use your code with 4 different words and 4 different colors. Am I right in thinking that because you have put '==' (strictly equal to the word in the string) it means that if there is a comment field in the table and by chance there is a sentence that includes the world 'High' (among other words) it will not trigger the color change?
    – susan
    Jul 14, 2017 at 10:48
  • Correct. The IF condition in the above code is looking for an exact match with in the matched TAG. There is a different way to check the occurrence of a word - check here w3schools.com/jsref/jsref_indexof.asp
    – HarryB
    Jul 14, 2017 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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