I'm writing a little library that should be used by people who don't know anything about programming, and it should add "complex" html component with one or two javascript lines (like a form with some inputs and texts to insert email and other credentials).
It's possible to "self-identify" script position to add element to DOM in that position? I mean, for example, in a code like this
<div>
<p> ... </p>
<script>
// my code is here
</script>
<a> ... </a>
...
</div>
I want to add an element in the position where script is written (son of div and after p), assuming that no element has specific id. Is it possibile?
Unfortunately document.write() is the only way to do this.
You could abuse this to get the containing element though by creating an element with a unique ID and then accessing the .parentNode of this element.
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