Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!