kbulens
11 years agoGuide
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,