Check if input is selected

HTML:

<div class="radio" id="uniform-L1"><span><input type="radio" name="length" class="radio" value="L1" id="L1"></span></div>

JS:

<script>
if(document.getElementById('L1').checked) {
         console.log("chwer");
        }
 </script>

I tried to find what’s wrong with my JS but I couldn’t. I have no console errors.

Answer

Listen for the change event if you want to log "chwer" everytime the radio button is checked:

document.getElementById('L1').addEventListener('change', function() {
  if (this.checked) {
    console.log("chwer");
  }
})
<div class="radio" id="uniform-L1"><span><input type="radio" name="length" class="radio" value="L1" id="L1"></span></div>