This topic contains 6 replies, has 2 voices, and was last updated by Sean Sean 2 years, 10 months ago.

jQuery in script tags and using $(document).ready() throughout the a page


  • tglore
    Participant

    Posts: 7
    Member Reply #4032

    Hello,

    First off I want to say that I love Metronic so far and after some tinkering I have been able to get most of it working with the codeigniter php framework as the back end.

    The problem I’m having probably has to do with the order/placement of loading the js script files but I can’t seem to find the correct order.

    If I place the following code on the page I get $ is not defined(or jQuery is not defined if I replace $ with jQuery):
    <script></script><script>

    $(document).ready(function() {

    alert(‘hello world’);

    });

    </script>

    How am I supposed to work around this or what do you recommend?  I would like to be able to include quick scripts on pages without having to load another/custom js file at the bottom of the page and have to use the init() setup you have in place. If it helps I could privately provide you with a link to my test site.

    Thanks,

     

    Tyson


    tglore
    Participant

    Posts: 7
    Member Reply #4033

    Woops,

    The line with “<script></script><script>” really should be just “<script>”

    Thanks

    • This reply was modified 2 years, 11 months ago by  tglore.
    • This reply was modified 2 years, 11 months ago by  tglore.
    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #4079

    Great! Glad to managed to fix it. If you need any further assistance please let us know.


    tglore
    Participant

    Posts: 7
    Member Reply #4084

    No my 2nd post was correcting my first post since I couldn’t edit it.  I still have the same problem, can you please help?

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #4101

    Hi,

    Please make sure jquery library is properly loaded in your page. It seems jquery is not being loaded and you are getting ‘jquery undefined’ error. If you need any further assistance please let us know which Metronic version you are using and if possible provide a test link to your developing site in a private reply. If you can’t provide us any test link then try to double check the HTML template and compare it with the original one to make sure all dependency js and css files are fully loaded.
    To go further you can use Chrome’s dev tools(CTRL+SHIFT+J) to debug your page and detect possible errors and issue from your page.

    Thanks.


    tglore
    Participant

    Posts: 7
    Member Reply #4200

    I found a fix for my issue here

    http://writing.colin-gourlay.com/safely-using-ready-before-including-jquery/

    This allows me to load jquery.min.js after the </body> tag AND I can use $(document).ready() anywhere on the page without error which was my problem.

     

    Thanks,

     

    Tyson

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #4210

    Hi,

    Looks great! Good luck with your project!

    Thanks.

Tagged: 

You must be logged in to reply to this topic.