Forum Discussion

kbulens's avatar
kbulens
Guide
11 years ago

jQuery is undefined

<script>
(function($){
console.log('ok');
jQuery('body').addClass('fr');
})(LITHIUM.jQuery);
</script>

 

 I added the above code in my header section, cause depending on language, i want to add a Class to it. Usefull for ex. css::after{content:"message in lang";}

None the less ... the console.log works, but i get a 'jQuery is undefined" (or "$ is undefined") ... what am i doing wrong.

  • Hi kbulens 

     

    If you want to use the jQuery provided by Lithium, I suggest to use the liaAddScript directive that we have to ensure that your script is executed once jQuery has been included on the page. Your code would change to :

     

    <@liaAddScript>
    ;(function($){
    console.log('ok');
    $('body').addClass('fr');
    })(LITHIUM.jQuery);
    </@liaAddScript>

     Hope this helps,

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi kbulens 

     

    If you want to use the jQuery provided by Lithium, I suggest to use the liaAddScript directive that we have to ensure that your script is executed once jQuery has been included on the page. Your code would change to :

     

    <@liaAddScript>
    ;(function($){
    console.log('ok');
    $('body').addClass('fr');
    })(LITHIUM.jQuery);
    </@liaAddScript>

     Hope this helps,

  • Alternatively , if you have installed anther piece of Jquery , you can change LITHIUM.jQuery to JQuery or leave it blank