Reputation: 9644
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?
Upvotes: 3
Views: 395
Reputation: 318688
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.
Upvotes: 1