I'm explicity not looking for the remove()
function.
A jQuery-Object not related to the DOM can be created using this:
let $element = $('<div>').addClass('myInvisibleDomObject').text('Test');
This unrelated object is appended on keypress to my DOM, but should be unappened when releasing the key.
I'm using this for an static object which represents the camera access. So my object is an video element, with stream data, video src, etc. So it's a little bit more complex than the code sample above. I do not want to clone the video object or create a new stream, because this is to slow.
I already tried appendTo(null)
, but this does not work. Simply hiding is no workaround, because some of the html is replaced via xhr requests on demand. I want a clean solution an no append to some other object like the <body>
or something like this.
Example:
// $element is the element from above
// .cameraPreview is some div inside my DOM
$(document).keydown(function(event: JQuery.Event) {
$element.appendTo('.cameraPreview');
});
$(document).keyup(function(event: JQuery.Event) {
$element.unappendFrom('.cameraPreview'); // this does not exist
});
addClass
will not create the element in the DOM?append()
,appendTo()
or something like this. Before the element is not visible in the DOM (and not rendered). But in my camera example a video stream from a camera can use an also unappended canvas to create screenshots.append()
... but however I will add it to my question.