html - If all elements don't have a particular class, then apply styles -
i have list of elements class name of .box . sometimes, element have class, not know element has it. is there way check if elements of .box don't have .extraclass , apply styles .box , if elements of .box has class .extraclass , don't apply css style? i want using css only. jsfiddle var toggleclass = document.getelementbyid('toggleclass'), box = document.getelementsbyclassname('box'), randomnumber = -1; toggleclass.addeventlistener('click', function() { if (randomnumber !== -1) box[randomnumber].classlist.remove('extraclass'); randomnumber = math.floor(math.random() * 9); box[randomnumber].classlist.toggle('extraclass'); }); removeclass.addeventlistener('click', function() { if (randomnumber !== -1) box[randomnumber].classlist.remove('extraclass'); }); #wrapper { padding: 0; margin: 0; display: flex; justify-content: center; flex-wrap: wrap; } .box { backgroun...