I have several elements in dom with the class .blockbadge , if the value of any .block-badge is 0, then I want to add the class to this element so that its style is different.
My JS adds a class to all of these elements if any of them is 0. How to do this, it affects only those elements that are zero?
HTML
<span class="block-badge">1</span> <span class="block-badge">0</span>
Js
var blockBadgeVal = $('.block-badge').val(); if (blockBadgeVal < 0) { $('.block-badge').addClass('zero'); }
source share