Find DOM position of <script> section

I am writing a small library that should be used by people who know nothing about programming and it should add a "complex" html component with one or two lines of javascript (for example with a form with some inputs and texts insert email and other credentials ).

Is it possible to "self-determine" the position of a script to add an element to the DOM at that position? I mean, for example in code like this

    <p> ... </p>
         // my code is here
    <a> ... </a>


I want to add an element at the position where the script is written (son of div and after p), assuming that no element has a specific id. Is it possible?


source to share

1 answer

Unfortunately, this document.write()

is the only way to do it.

You can abuse this to get the contained element by creating an element with a unique ID and then accessing .parentNode

that element.



All Articles