1
I am trying to make a bingo in HTML/Javascript and at the moment I need to delete a table (card) registered as soon as the user click on the delete button, as I am a beginner in Javascript I went to several websites and tested several commands but none worked, anyone who knows help me. Here comes the code:
<!DOCUMENT html>
<html lang="pt-br">
    <head>
        <meta charset="utf-8">
        <style>
                #container {
                    display: flex;
                    flex-wrap: wrap;
                  }
                table {
                    border: 1px solid black; 
                    margin: 10px;
                    vertical-align: bottom;
                }
        </style>
    </head>
    <body>
        <input type="text" id="nome">
        <input type="button" name="Criar" value="Cadastrar" id="botao">
        <div id="container"></div>
        <script> 
                var nome = window.document.getElementById('nome')
                var botao = window.document.getElementById('botao')
                botao.addEventListener('click',clicar_botao)
                function clicar_botao(){
                    var elemento_bisavo = document.getElementById('container');
                    var elemento_avo = document.createElement('table');
                    var elemento_pai = document.createElement('tr');
                    var elemento_filho = document.createElement('th');
                    var elemento_filho2 = document.createElement('th');
                    var botao_apaga = document.createElement('input');
                    var texto = document.createTextNode(nome.value);
                    elemento_avo.setAttribute("id","avo");
                    botao_apaga.setAttribute("type","button");
                    botao_apaga.setAttribute("value","Apagar");
                    botao_apaga.setAttribute("id","apagar");
                    botao_apaga.setAttribute("onclick","click");
                    function click(){
                        document.getELementById('avo').style.display="none";
                        document.getElementById('avo').style.display="hidden";
                    }
                    elemento_filho.appendChild(texto);
                    elemento_filho2.appendChild(botao_apaga);
                    elemento_bisavo.appendChild(elemento_avo);
                    elemento_avo.appendChild(elemento_pai);
                    elemento_pai.appendChild(elemento_filho);
                    elemento_pai.appendChild(elemento_filho2);
                }
        </script>
    </body>
</html>
NOTE: the code to delete the table should be inside the click function, the most I found was a property to make the table invisible, but still does not work.
/ Have you tried?
function click(){
 document.getELementById('avo').remove();
 document.getElementById('avo').remove();
 }– Maury Developer
I found this, I’ll test agr
– Akali
If it works, give me a reputation ,I’ve published my answer. I hope I’ve helped.
– Maury Developer