Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda