Why is that when i give alert inside the jquery block it runs other wise it doesn’t show any output?
<script type="text/javascript">
(function map() {
var test = document.createElement('script');
test.type = 'text/javascript';
test.async = true;
test.src = 'myjsfile.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(test, s);
});
</script>
I am trying to create a plugin and the script calls the myjsfile.js and will execute the functions inside it only is if i add alert() inside the above code.
If the code that you show is the first script tag on the document, I could see this maybe causing a problem:
Why not append it directly to the head or body? More straightforward, in my opinion.
Also, you may not be getting any output because you aren’t actually calling your function. Try this:
One other thing to watch out for,
mapis already a function within jQuery, so be cautious with your name spaces and how you try to call your function.