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

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -