I got a really bothering problem which I can not understand.
I have a div
which contains 2 paragraphs, and a clickable button to delete the first p
element, but the strange thing is that the button deletes it self and the p
element continues to live!
This is the result of my code:
But when I click on the button I get this:
Below is my code:
<div>
<p id="id_1">The first paragraph.</p>
<p id="id_2">The second one.</p>
</div><br>
<button onclick="remove(document.getElementById('id_1'));">click me!</button>
<script>
function remove(elem)
{
var parent=elem.parentNode;
parent.removeChild(elem);
}
</script>