After using . innerHTML to fill a DIV, how to clear that div with another function?

Asked

Viewed 412 times

0

I have the following code,

var resultado;
    var numero;
    var tamanhoNumero;
    var i=0;
    function calcular(){

        numero = document.form.numero.value;
        console.log(numero);
        tamanhoNumero = numero.length;
            console.log("i = " + i);

        for (i = tamanhoNumero; i>=0; i--) {
            console.log("i = " + i);

            console.log("numero.lenght = " + numero.lenght);
            resultado += numero.substring(i, i-1) + '<br>';
        }

        document.getElementById('saida').innerHTML = resultado;
    }

When I fill in the 'output', I would like to clean it before the next operation, this can be done at the beginning of this same function. How to do ?

  • Don’t just put resultado = '' in the first line of the function?

  • That’s it, thanks, I was trying with double quotes.

  • 1

    Just so we can honor Soen in numero.lenght length is poorly written

  • 1

    Single or double quotes there is no difference. You were possibly missing something else.

1 answer

0


Other similar forms of remove text from a tag without other child elements would be:

elemento.removeChild(elemento.firstChild);

or

elemento.removeChild(elemento.lastChild);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.