I have this piece of code:
<textarea id="test" style="width: 400px; height: 100px"></textarea>
<script>
var inserting = document.createElement("div");
document.insertBefore(inserting,document.getElementById("test"));
</script>
Which should insert DIV id=inserting
before textarea id=test
, but this error occurs
Node was not found" code: "8
I use FireFox 3.6 with Firebug on WinXP. Where is the problem?
insertBefore
needs to called on the parent element of the element before which is inserted:
<textarea id="test" style="width: 400px; height: 100px"></textarea>
<script>
var inserting = document.createElement("div");
var insertAt = document.getElementById("test");
insertAt.parentNode.insertBefore(inserting,insertAt);
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With