Is that possible to know where is a jQuery function launched from ?
<div>
<script language="javascript">
$(document).ready(function () {
whereAmI($(currentDIV));
});
</script>
</div>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is nothing saved for you about the DOM location whence the currently executing JavaScript was loaded. However, you can use the fact that scripts are executed as they are loaded to achieve this memory:
Here,
$('script').filter(':last');refers to the last script element on the page, which at the time of execution is the “current script”. Note that for each script I want to remember, I’ve named the variable housing the script object differently, otherwise it will be clobbered by subsequent scripts. An alternative would be to wrap each script in an immediately executed anonymous function, for the luxury of binding a localthisScriptvariable.