How can I create a HTML-Element dynamically, do something with it and then it should be removed. But it is important that it will be really deleted. Here is my approach:
var newdiv = document.createElement('div');
newdiv.setAttribute('id','MyDiv');
$('#MyDiv').css({'width':'100px','height':'100px'});
$('#MyDiv').html('This is a test');
$('#MyDiv').remove(); // It should be work ?
// Is it possible to delete it as follows?
newdiv.remove();
As I mentioned, it is important to really delete the element, since the Function "createElement()" can often get invoked.
How can I test whether the new created HTML-Element is really removed?
I test as follows, whether the element is still existed, but I get always true!
alert( $('#MyDiv').length == 1);
Below are a two links, but they were not enough for, in order to solve my problem.
setting the id attribute of an input element dynamically
createElement and delete DOMElement
Thanks.
newdiv.parentNode.removeChild(newdiv).#MyDiv, but$('#MyDiv')gets the element with the IDMyDiv