The operation to remove the child element could not be completed

var first_content = document.getElementById('first-content'),
offered_games = document.getElementById('offered-games');

for(var i = 0, e = offered_games.children; i < e.length; i++) {
  e[i].onmouseenter = function() {
    var img = document.createElement('img');
    img.src = this.children[0].children[0].src;
    img.classList.add('added-promotion');
    first_content.appendChild(img);
    setTimeout(function() {
      img.style.opacity = 1;
    }, 10)
  }

  function removeImg(img) {
    setTimeout(function() {
      first_content.removeChild(img)
    }, 300)
  }

  e[i].onmouseleave = function() {
    var added_promo = document.querySelectorAll('.added-promotion') || document.querySelector('.added-promotion');

    for(var i = 0, e = added_promo; i < e.length; i++) {
      e[i].style.opacity = 0;

      removeImg(e[i])
    }
  }
}
.first-content .img#img-player {
  height: 100%;
  width: 100%;
  background-image: url('');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

.first-content #offered-games {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 980px;
  position: absolute;
  z-index: 8;
  bottom: 180px;
  left: 50%;
  margin-left: -490px;
}

.first-content #offered-games .game {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 235px;
  margin-left: 9.3px;
  vertical-align: bottom;
  display: inline-block;
  cursor: pointer;
}

/* More CSS code here */

<div id="first-content" class="first-content">
  <div id="img-player" class="img"></div>
  <div id="offered-games">
    <div data-info="sportsbook" class="game sportsbook">
      <div class="top"><img src="http://0.tqn.com/d/worldsoccer/1/L/u/M/-/-/451274454.jpg"></div>
      <div class="bottom">
        <div class="text">
          <p class="title">Game 1</p>
          <p class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.</p>
        </div>
      </div>
    </div>
    <div data-info="poker" class="game poker">
      <div class="top"><img src="http://cache4.asset-cache.net/gc/492689397-soccer-player-standing-on-pitch-gettyimages.jpg?v=1&c=IWSAsset&k=2&d=%2F7DaYEj3tOfsAmZVQjUjN%2Fp85xL5t%2FRvXvNDXWwcD%2BWLs1oLsXFGW8D%2BBw37QVMl96M1ZTHpoFW9f6CnK92rTg%3D%3D"></div>
      <div class="bottom">
        <div class="text">
          <p class="title">Game 2</p>
          <p class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.</p>
        </div>
      </div>
    </div>
  </div>
</div>

Error:

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

Encountering an error when hovering quickly, but functions properly with slower hover speed.

Seeking assistance to resolve the recurring error and ensure smooth functioning. Thank you!

Answer №1

Replace first_content.removeChild(img) with img.remove() - this way you won't have to concern yourself with the correct parent element. If the remove method isn't supported in the browser you're using, use img.parentNode.removeChild(img)

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

"Utilize jQuery to superimpose an image on top of

I'm attempting to create a feature where clicking on an image will reveal text underneath, similar to how retailmenot.com displays coupon codes. In addition, when the image is clicked, users should be directed to an external URL. Here is an example o ...

Determining the Width of a DIV Dynamically with CSS or LESS Depending on the Number of Siblings

One of my challenges involves a parent DIV with a width set to 100%. Dynamically, this parent DIV is filled with numerous children DIVs. I am trying to calculate and assign their widths using only the calc method in CSS or LESS. This is because the flex ...

What is the best way to handle the resolution of multiple promises as they complete?

Suppose I have three different promises each taking a varying amount of time to resolve - 1000ms, 2000ms, and 3000ms respectively. How can I simultaneously start all the promises and handle them as they get resolved? For instance: let quickPromise = new ...

Leveraging AngularJs by binding ng-model to data from a JSON

Below is the code for a dropdown selection: <h3>Selectize theme</h3> <p>Selected: {{produk.category}}</p> <ui-select ng-model="produk.category" theme="selectize" ng-disabled="disabled" style="width: 300px;"> <ui-se ...

The Next.js API endpoint is struggling to process cross-domain POST requests

Dealing with a POST request in my NextJS application has been challenging. This particular post request is originating from a different domain. To address this issue, I included a receptor.ts file in the /pages/api directory: import { NextApiRequest, Next ...

JavaScript - Error: The '}' token was unexpected

Every time I attempt to move <div id="test">this should go down</div> downwards using: <div onclick="(".test").slideDown(800);">close it</div> I encounter an error whenever I click 'close it' SyntaxError: Unexpected to ...

I am facing a dilemma with Expressjs when it comes to managing numerous users simultaneously

I'm grappling with a conceptual dilemma as I delve into the world of building an expressjs app. My goal is to create a system where each user, upon starting the app, has their own temporary folder for storing various files. Despite my lack of experien ...

Is there a way to create a Vue.js component that retains the data I have added to it even when transitioning between routes? Currently, whenever I switch routes, the component deletes all the previously

I'm currently working on a webshop using Vue.js. When I add products, I utilize an event bus to pass the data to the CartComponent. Everything works as expected; however, if I navigate back or reload the page, all the data in my CartComponent gets del ...

Tips for successfully parsing JSON data during an Ajax call

After making an Ajax call, the response.responseText I receive looks like this: . "[ columns :[ { "id":"name", "header":"User name" }, { "id":"birth", "header":"Date of birth" } ], ...

Ensuring the next tab is not accessible until all fields in the current tab are filled

I am working on a form with a series of questions displayed one at a time, like a slide show. I need help with preventing the user from moving to the next set of questions if there is an empty field in the current set. Below is the script I am using to nav ...

PHP move_uploaded_file() function encountering an issue

As a newcomer to PHP, I am exploring the move_uploaded_file() function. I initiate an HTTP POST request from JavaScript/jQuery to a PHP file hosted on a Microsoft Azure server. The request includes an audio blob like so... mediaRecorder.ondataavailab ...

How to display a variety of JSON data in different templates with unique variables using angularjs

I am curious about the best approach to handling a response that contains various types of objects presented like this: [ {"nodeClass":"Entity", "text":"foo","entityfield":"booz"}, {"nodeClass":"User","username":"bar","userfield":"baz"} ] Each type of ob ...

Vue router beforeRouteEnter - when the page is refreshed, the button label vanishes

<script> export default { name: 'TEST', data() { return { prevRoute: '' } }, methods: { goBack() { return this.$router.go(-1); }, }, beforeRouteEnter(to, from, next) { next(vm => { ...

Implementing line breaks in JSON responses in an MVC application

I am looking to show a JavaScript alert with line breaks using the message returned from a controller action that returns JSON result. I have included "\n" in the message for line breaks. Below is the code snippet from my controller: [HttpPost] publ ...

Customizing the style of an element in Vue depending on the size of the window

I am struggling to update the appearance of an HTML element when the window size is below 500px. Currently, I have a computed property that sets a background-image for the element. I attempted to use an if statement within the computed property to check if ...

Ensure the footer remains fixed while scrolling

For the past day, I've been tackling a challenge with my online shop project. On the specific item's page, I want to include a fixed [add to cart] button as a footer initially, which then becomes sticky when scrolling to a certain point. You can ...

Grunt is throwing an error message of "Cannot GET/", and unfortunately ModRewrite is not functioning properly

I've recently started using Grunt (just began last Friday). Whenever I run Grunt Serve, it displays a page with the message "cannot GET/" on it. I tried implementing the ModRewrite fix but the error persists. Any assistance would be highly appreciat ...

Combine the values in the array with the input

I received some data from the back-end which is being written to a form, and it's in the form of an array of objects Below is the code snippet: this.companyDetailsForm = new FormGroup({ directors : new FormControl(response?.companyDirectors) ...

Sending data to a function that is generated dynamically within a loop

How can I ensure that the date2Handler is triggered with the corresponding date1 and date2 values from the month in which the date1 change occurred? Currently, whenever the date1 value is changed in any month, the date2Handler is called with the "month" t ...

IE/Firefox returning empty value for Ajax requests

After spending two days trying to solve the issue, I still can't figure out why this code is failing in IE (v11) and Firefox while working fine in Chrome. I have read many questions on similar topics involving caching problems with multiple Ajax call ...