When dealing with arrays, the parentElement.remove() function may not be defined

Query: e1.parentElement.remove(); is not defined

debug: e1 contains a value. e1.remove() removes a button, however, I need to remove a group of buttons.

global variable and function execution

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

primary function featuring both inquiries and predetermined user responses that can be selected

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

    let BotQuestions = [
        ['Select the topic or write your question below.'],
        ['Before we start, our legal team requires us to inquire 😅 <br/><br/> Do you consent to LiveChat, Inc. processing your personal data?', 'Click the button below to view our Privacy Policy.'],
        ['Great, let me ask a few questions to connect you with the appropriate representative :)']
    ];

    let UserOptions = [
        ['Contact Sales', 'Free Trail', 'Getting Started', 'Features', 'Pricing', 'Contact support'],
        ['Agree', 'Disagree'],
        ['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);
}

delete buttons and display the clicked button

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);
    }
   
}

Answer â„–1

Understood, it appears that consolidating all buttons within a div resolved the issue.

        var selection = UserSelections[y];
        let userHtml = '<div style="padding: 15px !important;">';
        for (var uy = 0; uy < selection.length; uy++) {
            userHtml += '<button style="margin-bottom: 10px !important" type="button" class="btn btn-lg btn-default" onclick="AllResponses(this,\'' + selection[uy] + '\')">' + selection[uy] + '</button>&nbsp&nbsp&nbsp';
        }
        userHtml += "</div>";
        $("#chatbox").append(userHtml);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking for a Hack to Integrate a Music Player into Your Website?

Currently, I am utilizing the Jplayer plugin from JQuery to incorporate an Audio player into my website. I have come across a situation where: If the user is not currently listening to any music while browsing the website, the page can load without any i ...

"Troubles encountered while trying to save JSON information on NodeJS Express platform

I've encountered an issue with saving and accessing my JSON data - all objects in the JSON file are being converted to strings, even numbers. Below is my express route for retrieving data from an HTML form: control.post('/like/:id', getuser ...

Is it possible to update only the inner text of all elements throughout a webpage?

Scenario After coming across a thought-provoking XKCD comic, I decided to craft a script that would bring the comic's concept to life: javascript:var a=document.getElementsByTagName('body')[0].innerHTML;a=a.replace(/Program(\w\w+ ...

Discover the process of utilizing doc.getElementbyClassName to determine if any of its elements are blank

On my HTML invoice table, I sometimes have empty elements that cause the row to misalign. To fix this, I want to add whitespace if an element is empty. Here is the structure of the table: <div class="invoiceTable"> <div class="titles2" style=" ...

The modal window pops up immediately upon the first click

Experience a dynamic modal element that springs to life with just the click of a button or an image. The magic lies in the combination of HTML, CSS, and jQuery code: <div id="modal-1" class="modal"> <div class="button modal-button" data-butto ...

jQuery MaskMoney - position input at the start of the field

Check out this jsfiddle I created to showcase the issue I'm facing. Whenever I click on the input field, the cursor automatically goes to the end. This means that I have to start typing cents before dollars, which is not the behavior I want. My desire ...

Does Koa.js have a nested router similar to Express?

Are there any libraries available that offer Express-style nested routers? For example: var koa = require('koa'); var app = koa(); var Router = require('???'); var restApiRouter = Router(); restApiRouter.get('/', function*() ...

Connecting to a pathway of Material-UI menu items

I am currently utilizing Material-UI's menu components as part of my project requirements. However, I am encountering difficulties in properly routing each MenuItem to an existing route within my application. As a temporary solution, I have resorted ...

The $scope variable does not sync with the express API

I have noticed that the static part of my app is loading fine. Recently, I integrated a service using Express as a simple API. However, when I attempt to set the #scope from my module's controller, it seems like it hasn't loaded at all. I am puzz ...

In jQuery, you can arrange an array in order and retrieve the first key

I have an array with key-value pairs and want to sort it by value, then retrieve the key of the first value. var obj = { fruit:5, vegetable:3, meat:7 }; var tempArr = [ ]; $.each(obj, function(key, value) { tempArr.push({k: key , v:value}); }); tempArr.s ...

Transform the words in a string into an array

I'm scratching my head trying to find a solution on Stack Overflow, but nothing seems like the right fit. Can anyone provide some guidance? I need a regex that will enable me to use JavaScript split to break a string into an array. The test case is: ...

Defining a Global Variable using the jQuery $(this)

I have been looking for ways to simplify my coding process, and one method I've tried is assigning a global variable. var parent = $(this).parent().parent().parent(); var parentModule = $(this).parent().parent().parent().parent(); Throughout my code ...

Guide on building a REST API with Node.js Express.js and OracleDB to perform database updates

Looking for assistance with creating an API in Node.js to fetch and update data on the frontend. I am able to retrieve data using the provided code, but facing challenges updating it. React.js is being used for the frontend. var express = require("expr ...

Instructions on how to retrieve a JSON file from an external source

I'm experiencing difficulties in downloading a json file from an external URL using nodejs. The issue arises when the downloaded file (dumpFile.json) is created empty. var file = fs.createWriteStream("download/dumpFile.json"); let URL = 'http:// ...

Switching code from using .hover() to using .click() while still maintaining the functionality of both.orChanging code to switch

How can I change this script to trigger on click and also maintain the hover functionality: $x = jQuery.noConflict(); $x(document).ready(function () { $x(".swatch-anchor").on('click hover', function () { var newTitle = $x(this).attr( ...

Passing a parameter from a redirect function to an onClick in React using TypeScript

I am facing a challenge in passing a parameter to my redirectSingleLocker function. This function is intended to take me to the detailed page of a specific locker, identified by a guid. The lockerData.map method is used to display all the JSON data in a ta ...

I aim to prevent users from liking a post multiple times within Firebase

I came up with this code snippet to implement the Like functionality: /*Incrementing by 1 every time a user submits a like*/ db.collection("post").doc(postId).update({ likes: increment }) /*Collecting the UID of the user who submitted the l ...

The issue of jQuery not functioning properly within a Rails environment

Despite my efforts, I am still struggling to make jquery work in rails. I have installed the 'jquery-rails' gem and added the require statements in the application.js file. Below is a sample test page that I have been testing: <!DOCTYPE htm ...

To add additional nested data to a JSON object in JavaScript, you can use the push method or update

Looking to enhance the nested object data within my existing object The current structure of the JSON object array resembles this: var orderDetails = [{ "utilityType": "Electric", "firstName": "ROBERT", "lastName": "GUERRERO", "utilityList": [{ ...

What is the method of showing a leaflet map in a particular div tag?

I want to showcase a leaflet map, but I specifically need it to be displayed in a div tag with a particular id like document.getElementById("map"). Here is the code snippet below which utilizes Vue.js: Here is the div tag where the map will be rendered: ...