Jump to content

How to embed Jquery

Guest
Go to solution Solved by Guest,

I came across this (i was doing it wrong)

(function(){var startingTime = new Date().getTime();var script = document.createElement("SCRIPT");script.src = '/src/js/jquery.js';script.type = 'text/javascript';document.getElementsByTagName("head")[0].appendChild(script);var checkReady=function(callback){if(window.jQuery){callback(jQuery);}else{window.setTimeout(function() { checkReady(callback);},20);}};checkReady(function($){$(function() {
  
  //run jquery code here
  
  });});})();

 

So i have been having trouble with this for a while and need some help. im trying to run Jquery (local) from Inside another script. I keep getting the "$ is not ..." jquery didnt load. Any way to go about this>

ex:

    (function() {
        // Load the script
        var script = document.createElement("SCRIPT");
        script.src = '/src/flyer/jquery.js';
        script.type = 'text/javascript';
        script.onload = function() {
            var $ = window.jQuery;
            // Use $ here...
        };
        document.getElementsByTagName("head")[0].appendChild(script);
    })();
//output
console.log("jquery not found/loaded $ is not defined") 

Im calling from /src/js/init.js . I only want the 1 init scipt to add jquery, while not having to put <script src="wfwfw">  on every page.

Link to comment
Share on other sites

Link to post
Share on other sites

I came across this (i was doing it wrong)

(function(){var startingTime = new Date().getTime();var script = document.createElement("SCRIPT");script.src = '/src/js/jquery.js';script.type = 'text/javascript';document.getElementsByTagName("head")[0].appendChild(script);var checkReady=function(callback){if(window.jQuery){callback(jQuery);}else{window.setTimeout(function() { checkReady(callback);},20);}};checkReady(function($){$(function() {
  
  //run jquery code here
  
  });});})();

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×