Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
parentElement.remove() is undefined when working with array

Issue: e1.parentElement.remove(); is undefined

debug: e1 has a value. e1.remove() remove a button, but i need to remove group of buttons.

global variable & run function

var x = 0;
AllResponses(null, null);

main function which has bot questions, and pre-made user answers, where user can click on

function AllResponses(e1, userPicked) {
    //user responsed 
    if (e1) {
        PrintUserResponse(e1, userPicked);
    }

    let BotQuestions = [
        ['Select the topic or write your question below.'],
        ['Before we start, our legal made us ask 😅 <br/><br/> Do you agree to have your personal data processed by LiveChat, Inc.?', 'Click the button below to see our Privacy Policy.'],
        ['Great, let me just ask a couple of questions so I can find the right rep for you :)']
    ];

    let UserOptions = [
        ['Contact Sales', 'Free Trail', 'Getting Started', 'Features', 'Pricing', 'Contact suppot'],
        ['Agree', 'Disgree'],
        ['Dave']
    ];

   setTimeout(() => {
    // Bot question 
    if (x != BotQuestions.length) {
        var question = BotQuestions[x];
        for (var y = 0; y < question.length; y++) {
            let botHtml = '<p class="botText"><span>' + question[y] + '</span></p>';
            $("#chatbox").append(botHtml);
        }

        // user option 
        var option = UserOptions[x];
        for (var uy = 0; uy < option.length; uy++) {
            let userHtml = '<button type="button" class="btn btn-small btn-primary" onclick="AllResponses(this,\'' + option[uy] + '\')">' + option[uy] + '</button><br/>';
            $("#chatbox").append(userHtml);
        }
        x++;
    }
}, 1000)

    document.getElementById("chat-bar-bottom").scrollIntoView(true);
}

remove buttons, & show which button was clicked on

function PrintUserResponse(e1, userPicked) {
    if (e1) {
        alert(e1.parentElement.remove());

        //remove pre options
        e1.parentElement.remove();

        //user pre-option
        let userHtml = '<p class="userText"><span>' + userPicked + '</span></p>';
        $("#chatbox").append(userHtml);

        document.getElementById("chat-bar-bottom").scrollIntoView(true);
    }
   
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

got it, seem like i had to group all buttons into a div. than it works fine.

        var option = UserOptions[x];
        let userHtml = '<div style="padding: 15px !important;">';
        for (var uy = 0; uy < option.length; uy++) {
            userHtml += '<button style="margin-bottom: 10px !important" type="button" class="btn btn-lg btn-default" onclick="AllResponses(this,\'' + option[uy] + '\')">' + option[uy] + '</button>&nbsp&nbsp&nbsp';
        }
        userHtml += "</div>";
        $("#chatbox").append(userHtml);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda