I have a list and I’m checking if the list item has two specific classes. If it does, I want to change the background of that list item to blue. however my code doesn’t seem to work. How can I target that specific list item? The alert works fine, it’s just the colour which doesn’t.
if (($("#all-colls-list li:contains(" + itemName + ")").hasClass("groupAdded")) && ($("#all-colls-list li:contains(" + itemName + ")").hasClass("selAdded")) ) {
$(this).css("background-color", "blue");
alert("has both classes");
}
Using class selectors instead of hasClass() will allow you to achieve what you’re looking for with a single selector, and to obtain references to the elements you want to modify: