fatti spostare in javascript

codice:
<script>
function delChar() {
  var testo = document.getElementById('testo');
  var len = testo.value.length;
  if (len > 0) {
    testo.value = testo.value.substring(0, testo.value.length-1);
  }
  else {
    alert('Il campo è già vuoto');  
  }
  
}
</script>

<input type="text" id="testo" value="html.it" />
<input type="button" value="cancella" onclick="delChar();" />

Ciao