I have some th
s that I know the text
value of. I want to apply a class to a certain list of these th
s.
What I have works like a charm, I just want to see if there's a better way to write it.
//Custom extended jQuery psuedo function to check if text() of elem is exactly some string (ensures it doesn't overwrite existing fn)
//Ref: https://stackoverflow.com/a/18462522/2402616
$.expr[':'].textEquals = $.expr[':'].textEquals ||
$.expr.createPseudo(function(arg) {
return function( elem ) {
return $(elem).text() === arg;
};
});
const textsOfThsToAddClassTo = ['foo','bar','fizz',buzz'];
//Here's where my question really is
textsOfThsToAddClassTo.forEach(text => {
$(`th:textEquals('${text }')`).addClass('my-class');
});
I'm just wondering if there's a better way to write that forEach
part. Like, if I can use a selector to only contain what's in the array. Thanks!