Why cant Dollar symbol be used as an alternative fo jQuery in Wordpress?

前端 未结 3 870
难免孤独
难免孤独 2020-12-17 22:27

Why can\'t we use \"$\" instead if jQuery in wordpress? Usually \"$\" is the alternative of jQuery right? But in Wordpress it shows \"$\" is not a function.

相关标签:
3条回答
  • 2020-12-17 22:42

    jQuery(...) should be used instead of $(...)

    Edit ---- sorry, i misread your question. It depends on the jquery implementation of your wordpress version. I have seen wordpress sites that allowed the usage of $ before, but i don't really know what it depends on.

    0 讨论(0)
  • 2020-12-17 22:46

    Have a look at tip 5 in this web page: 5 Tips for using jquery with wordpress:

    It is important to know that the version of jQuery that comes with WordPress automatically calls the jQuery.noConflict(); function, which gives control of the $ variable back to whichever library first implemented it. If you are loading a different copy of jQuery, you'll need to manually call jQuery.noConflict();, if necessary, from one of your JavaScript files.

    I hope that helps.

    0 讨论(0)
  • 2020-12-17 22:53

    The tricky thing is this particular copy of jQuery is in compatibility mode by default. That means that the typical ‘$’ shortcut for jQuery doesn’t work, so it doesn’t conflict with any other JavaScript libraries that use the dollar sign also, like MooTools or Prototype.

    Source: Using ‘$’ instead of ‘jQuery’ in WordPress

    0 讨论(0)
提交回复
热议问题