I am configuring in a datatable that the row changes color according to the value of the first column, but the value is not always the same, depending on the time there are different ones, here is the example:
if (data[0] == "MATEMATICAS 20:30")
{
$(row).addClass('td:eq(0)').css("background-color", "#e1f0d9").css("color", "#477540").css("font-weight", "bold");
}
I want all the ones that appear with the word MATHEMATICS to include them, regardless of whether they have text before or after them, I have tried changing them ==
for the other logical operators and even trying as in excel"*MATEMATICAS*"
You could use the function
indexOf
. This way, if it contained the word MATH, it would change your CSS.The function
indexOf
returns the index of the first occurrence of the word. In case it didn't find the word, it would return -1.NOTE: The function
indexOf
is case sensitive, that is, it takes into account upper and lower case letters. In case you don't want to be case sensitive you could use thetoUpperCase()
or functionstoLowerCase()
, which convert all text to upper or lower case respectively.I would change your initial idea and propose adding a subject class to each row identifier tr : type :
then, your css would have to declare those classes:
with that you would not directly need to use js.
You have two options:
1.-
indexOf()
https://www.w3schools.com/jsref/jsref_indexOf.asp
two.-
match()
https://www.w3schools.com/jsref/jsref_match.asp
You will have to take into account capital letters, accents, etc.