I want to highlight any element that has a class that starts with a_slot_
but doesn't end with pink
or green
in any of the class names. In this example the third element I feel like should be highlighted because it has class a_slot_orange
and the other class doesn't contain pink
or green
.
Why isn't the third element highlighted (but the last is)? How do I highlight the third with the others?
$(document).ready(function() {
$("[class^='a_slot_']").each(function(i,v){
if(!$(this).attr('class').includes('green') && !$(this).attr('class').includes('pink')){
$(this).css('background-color', 'red');
}
});
// also don't work....have the same result
//$("[class^='a_slot_']:not([class$='green'],[class$='pink'])").css('background-color', 'red');
//$("[class^='a_slot_']").not("[class$='green'],[class$='pink']").css('background-color', 'red');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class='a_slot a_slot_green'>Green</p>
<p class='a_slot a_slot_pink'>Pink</p>
<p class='a_slot a_slot_orange'>Orange (shouldn't I be highlighed too?)</p>
<p class='a_slot_green'>Green</p>
<p class='a_slot_pink'>Pink</p>
<p class='a_slot_orange'>Orange</p>
<p class='a_slot_4'>4</p>
<p class='a_slot_16'>16</p>
<p class='a_slot_16 other_class'>16</p>
<p class='a_slot_orange other_class'>Orange</p>