html - Get element from which function is called in JavaScript -
is possible html element function called in javascript?
for example have in html:
<script type="text/javascript"> function myfunction() { var mycontainer = getelementfromwhichfunctioniscalled(); // possible? (mycontainer.id == 'my-container'); // true } </script> <div id="my-container"> <script type="text/javascript">myfunction();</script> </div>
thank you.
the way call here, when myfunction
running, document have been parsed script
element in #my-container
. because of that, can use
var scripts = document.getelementsbytagname('script'); var currentscript = scripts[scripts.length - 1]; var mycontainer = currentscript.parentnode;
to element.
Comments
Post a Comment