Skip to main content
1 de 2

Cannot read property 'value' of null

Criei uma função em javascript, porem me retorna o seguinte erro:

Cannot read property 'value' of null

Segue um pedaço do código:

HTML

        <input type="text" name="" id="letra2" class="input-text" maxlength="1">
        <input type="text" name="" id="letra3" class="input-text" maxlength="1">
        <input type="text" name="" id="letra4" class="input-text" maxlength="1">
        <input type="text" name="" id="letra5" class="input-text" maxlength="1">
        <input type="text" name="" id="letra6" class="input-text" maxlength="1">
        <input type="text" name="" id="letra7" class="input-text" maxlength="1">
        <input type="text" name="" id="letra8" class="input-text" maxlength="1">
        <input type="text" name="" id="letra9" class="input-text" maxlength="1">
        <input type="text" name="" id="letra10" class="input-text" maxlength="1">

function defineLetrar() {
    var obj;
    for (var i = 0; i <= 10; i++) {
        let obj = document.getElementById(`letra${i}`).value = ''
        console.log(obj)
        //obj = document.getElementById('letra'+i).style.display = 'none';
    }
}```