1

I simply have a table with a bunch of ✔ X and a few other symbols, how can I change the class of a cell based on it's contents?

jQuery example:

$(function(){$("td:has('✔')").addClass("tick"); });
$(function(){$("td:has('X')").addClass("cross"); });

2 Answers 2

2

This is also covered in post jQuery select based on text.

You can widdle down the set of TD elements to only those td elements whose text exactly matches your expectations.

$("td")
  .filter
  (
    function()
    {
      return $(this).text() === "✔";
    }
  )
  .addClass("tick");
Sign up to request clarification or add additional context in comments.

Comments

0

This seems to work fine if the cell contains the symbol...

$("td:contains('✔')").addClass("tick");

...but if we are looking for something like hyphen (-) how ca nwe determine this is the only content of the cell instead of just containing it?

Any better solutions?

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.