Can $ be used for jQuery?

2 replies · opened Jan 12, 2024

Mms4smanJan 12, 2024

It seems that by default, jQuery is being loaded, but that the $ keyword doesn't work out of the box. I see that all the custom jQuery in the template just uses jQuery keyword directly instead of $. Is there a particular reason for this? Is there a reason I can't use $? If I just install jQuery myself, $ works by default so it seems like this has been intentionally removed for some reason.

Is there any reason I shouldn't be able to just put


if (typeof jQuery != 'undefined') {
    $ = jQuery.noConflict()
}

after the template scripts load and use $ in my own code? It seems to work so far but I don't know if it will have negative side effects.

Thanks!

SSemicolon WebSTAFFJan 15, 2024

Hello,

Canvas by itself is compatible with Vanilla JS and jQuery usage is optional. There are Components which require jQuery and has been mentioned in the js/functions.js File. Additionally, jQuery (instead of the shorthand $) is being used for safe practises. You can certainly use $ if you like for your Custom Codes and there are no negative impacts for the same. However, we recommend using this:
[ch_pre type="js"](function ($) {

// Write your jQuery Codes here
// $(document).ready() etc. or Plugin Initializations

})(jQuery);[/ch_pre]

For additional documentations, consider checking: https://docs.semicolonweb.com/docs/getting-started/javascript/ .

Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Mms4smanJan 15, 2024

That helps! Thanks for the reply! Great template, thanks!

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard