I know that in Jquery you can get the event.id if I had triggered an event (click, etc) but how would I get the DOM location of a simple function call
Ex :
<pre id="container2">...
<script>
FunctionCall();
</script>
</pre>
I would like to get the “container2” value from inside my FunctionCall
In general, the script does not know where it was launched from so there is no generic way to do what you were asking. You will have to either find a container div that you know in advance or insert your own known object that you can then find.
In your specific example, you could do this:
Then, from within the script, you can find the DOM element with the id that was passed to it.
Or, you could put the
document.write()into the function itself so it marks its own location:This exact code would only work if FunctionCall was only called at page load time so the
document.write()would work as desired.