The code to remove the element is outside the plugin. I figured that the plugin should be able to clear it's Intervals even though it wasn't destroyed by the parent. Where I implement this would be the preferred way to do it.
I found a way to get it to work partially, but that spawned another problem. Currently I'm trying to understand the window.setInterval. I just can't figure out on what level this interval is and WHAT it is. For example, if I do the following: var interval = window.setInterval([something, something]); console.log(interval); // outputs a number And if I assign window.setInterval() to "interval" again I now seem to have two instances of an interval which seems also suddenly unclearable. I got the "is element still in the dom"-functionality to work by grabbing the original ID and checking $(element_id).length, but that isn't good enough since I should not rely on an element having an ID that also must be unique, and I don't want to assign a unique ID myself. That just seems improper. The most elegant solution would be if window.setInterval only could be one interval on each unique variable, but they seem to add together and cause interval-havoc if I don't make sure I clear them before reassigning, which I don't know how to do if the parent have deleted the dom-element on which the plugin was assigned. I'm flabbergasted.