Problema: e1.parentElement.remove(); es indefinido
depuración: e1 tiene un valor. e1.remove() elimina un botón, pero necesito eliminar un grupo de botones.
variable global y función de ejecución
var x = 0; AllResponses(null, null);función principal que tiene preguntas de bot y respuestas de usuario prefabricadas, donde el usuario puede hacer clic en
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); }eliminar botones y mostrar en qué botón se hizo clic
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); } }lo tengo, parece que tuve que agrupar todos los botones en un div. que funciona bien.
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>   '; } userHtml += "</div>"; $("#chatbox").append(userHtml);