Da in Joomla und Wordpress neben jQuery noch andere JavaScript Bibliotheken existieren, kann/muss man jQuery nicht mehr mit dem Dollarzeichen, sondern mit jQuery ansprechen. Für manche nur fünf Zeichen mehr, andere nervts.
So kann man es umgehen.
(function ($) {
console.log('now you can use the dollar sign $');
})(jQuery);
Mit document ready function:
(function ($) {
console.log('now you can use the dollar sign $');
$(document).ready(function () {
console.log('ready!');
});
})(jQuery);
Oder mit der Kurzschreibweise der ready function:
(function ($) {
console.log('now you can use the dollar sign $');
$(function () {
console.log('ready!');
});
})(jQuery);
Noch schöner/kürzer geht’s dann noch so:
jQuery(document).ready(function ($) {
console.log('now you can use the dollar sign $');
console.log('ready!');
});
Und hier die optmierteste Version:
jQuery(function ($) {
console.log('now you can use the dollar sign $');
console.log('ready!');
});