I’m trying to write a bookmarklet which involves dynamically adding two script tags, one for jQuery and the other for a js script written in jQuery. The problem I’m having is that even though I add the jQuery script first, js script isn’t able to be read because the browser says that jQuery is undefined. I know that the error is that jQuery is still being loaded as the browser adds my js script and as a result, the browser doesn’t recognize the jQuery in the js script when it is executing the js script. Is there anyway to delay the adding of the js script tag until after jQuery is completely loaded?
Thanks!
How do your script look like?
You should encapsulate everything you do in the script in a function, which you then call from the document.
For instance put everything in the function
myJqueryFunction()then call it with:That makes your code only to execute once jQuery have fully loaded.
Alternatively, you should be able to execute your script using Ajax, but keep in mind that your script have to be served from the same domain as the document, otherwise it will not have access to the DOM.