Forum Academy Marketplace Showcase Pricing Features

[PROBLEM] Building a Wistia Video Player Plugin

Hi everyone!
There was no Wistia Video Player plugin that would trigger the events i needed for the platform im building so i decided to build one myself!
I created a field “embed code” which i use to load a Wistia embed code referring to a video and showing it into my element.
To do that i use in my function update:
var embedded = properties.embedded_code;
instance.canvas.append(embedded);
The issue is when i try to replace the “embed code” with another one after the first one executed, my instance.canvas.append is placing itself exactly under the first embed code in the element code!
I tried this on an element action i called “reset”:
var embedded = properties.embedded_code;
instance.canvas.remove(embedded)
and tried to place it in the workflow, before the embed code of the second video is loaded but it didn’t work.
Does somebody know how i could fix this?
I dont have experience with JavaScript.
Here is my function update code


And here is how a Wistia Embed Code, which im appending to the element code, looks like: