Suppose I have a script tag :
<script src="https://example.com/test.js"></script>
I want to insert this script tag inside other HTML tags like : form
, div
, section
etc.
So If I insert script tag inside form tag :
<form>
<script src="https://example.com/test.js"></script>
</form>
https://example.com/test.js
should console the closest parent element, which is form
.
Similarly, If we insert script tag inside a div, it should console the closest parent element which is div
in this case.
Is there any way to achieve this ?