How to change the class of the block with JS?

Hello!
Can you please tell me what to add in code so that when value "XXX" is equal to "0" in the class box a is changed to "yes"? Thanks in advance!

XXX:<input id="xxx" value="5"><br>
<button id="action">action</button>
the <script>
let xxx = document.getElementById('xxx');
let action = document.getElementById('action');
action.onclick = function() {xxx.value = parseInt(xxx.value) - 1;}
</script>

<style>
#box {background-color: red; height: 100px; weight: 100px;}
.no {opacity: 0;}
.yes {opacity: 1;}
</style>
<div id="box" class="no"></div>
March 20th 20 at 11:41
1 answer
March 20th 20 at 11:43
Solution
Thanks, but no change! Added to the tag </script>. CANT? - marcelino_Gerlach commented on March 20th 20 at 11:46
@olen30, put a code sample on JSFiddle or CodePen, and that so soon it is not clear what the problem is - Kurt.Ma commented on March 20th 20 at 11:49
@olen30, probably at the time you execute that in the script element's box is not yet on the page. - jackson.Friesen25 commented on March 20th 20 at 11:52
@Daron76, please - marcelino_Gerlach commented on March 20th 20 at 11:55
@olen30, as I understand it, at zero value you had in mind is completely empty input, updated the answer - Kurt.Ma commented on March 20th 20 at 11:58
@Daron76, I meant, "0", the second option with an empty input - works - marcelino_Gerlach commented on March 20th 20 at 12:01
@olen30, AA there when you press the button you need something blunt today, updated the answer again - Kurt.Ma commented on March 20th 20 at 12:04
@Daron76, thank you! - marcelino_Gerlach commented on March 20th 20 at 12:07

Find more questions by tags CSSJavaScriptHTML