0

Is it possible with Javascript to get the DOM element surrounding my script tag?

Example:

<div>
    <script>
        // get the DOM element of the surrounding <div> tag here
    </script>
</div>

I won't/can't use id's or something similar on the div, because they would have to be randomly generated to be unique. I'm looking for a clean approach. There could be any number of these DIV's with Javascript inside.

drakanor
  • 107
  • 8
  • 1
    Have you tried any code? – Toiletduck Jan 29 '16 at 14:36
  • So you ***can't*** use IDs because of the unknown nature of them. That's fine. If you **could** but ***won't*** then that's all on you. – krillgar Jan 29 '16 at 14:37
  • I agree with @JamesThorpe. Read that and then select the parent of the script element. Edit: Here is the link he referenced - http://stackoverflow.com/questions/403967/how-may-i-reference-the-script-tag-that-loaded-the-currently-executing-script – Toiletduck Jan 29 '16 at 14:40
  • @Toiletduck Just FYI - when questions are closed as dupes, the links that were in the original comment end up in the yellow box at the top of the question - it didn't get lost during the process :) – James Thorpe Jan 29 '16 at 14:44
  • I see. The questioned hadn't been closed off on my screen yet, your comment was just gone so I figured I would post the link. But thanks for the info bud. – Toiletduck Jan 29 '16 at 14:45

0 Answers0