开发者

jQuery oddity in Wordpress

I'm getting started with Wordpress and trying to use jQuery as my JavaScript library of choice. I've got it loading with wp_enqueue_script but for some reason when the page actually loads the $ function it does so with it behaving like it does in Prototype (single dollar sign is "get by Id" and $$ is the CSS selector system).

I'm very confused as to why because I cannot find anywhere in the response from the server where the instruction to load Prototype is coming from; there is no <script> tag in the head or body that points to the library, and Firebug's list of loaded scripts does not include it. Has anyone else encountered this issue, and if so where is Prototype hiding?

Update

After having an idea, I tried something - the $ and $$ behavior is part of Wordpress's c开发者_运维技巧opy of jQuery 1.4.2: Loading the script from Google's CDN resolved the problem. So the new question is, "Why does Wordpress jQuery differ from normal jQuery?"


"Why does Wordpress jQuery differ from normal jQuery?"

WordPress loads jQuery in no conflict mode - another script on the page must've been tinkering with the $ surely?


Some things I might try in order to debug this:

  • Save Page As -> Web page, complete. Search the resulting directory for "Prototype".

  • Then start tinkering with your saved copy of the page. You could insert <script> tags at various points in the head of the document, trying to figure out at what point $ is set, or at what point its behavior changes.

  • Or, in Firefox, use this.watch("$", function () { alert(Error().stack); }) to see where it is set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜