8

I'm having some trouble getting jQuery to play nice with DokuWiki - has anyone already done this successfully?

At the moment, including jQuery reuslts in all sorts of JS functionality breaking, and I'm having trouble tracking down the source of the problem. What are some things to look for that tend to conflict with jQuery?

Wilco
  • 32,754
  • 49
  • 128
  • 160

4 Answers4

16

I'm not familiar with DokuWiki personally but if something is breaking just when you include jQuery then it's probably a conflict with the '$' variable in jQuery. You can use jQuery's noConflict method to get around that, more information here: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

See also this Stack Overflow post: jQuery & Prototype Conflict

Community
  • 1
  • 1
John Resig
  • 35,521
  • 3
  • 29
  • 19
  • 6
    AFAIK, the only items added to the global namespace are $ and jQuery (which are synonyms). Using noConflict() reduces this to jusy jQuery. Hopefully, DokuWiki doesn't reference anything named jQuery in the global namespace ;) – Adam Bellaire Jan 29 '09 at 21:54
6

There's also a plugin that adds JQuery to DokuWiki: http://www.dokuwiki.org/plugin:jquery

Andreas Gohr
  • 4,617
  • 5
  • 28
  • 45
6

You can usually avoid any jQuery conflicts by using the following right after you load jquery.js:

jQuery.noConflict();

Then, it won't overwrite the $ variable, which is most often the source of trouble in these JS library conflicts. You'll need to call jQuery functions using jQuery, though. Examples:

jQuery(function() { ... }); // $(function ...
jQuery(".klass").hide();    // $(".klass" ...
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
0
jQuery.noConflict();

Then you can use jQuery("your element selector") or whatever instead of $. To use the nicer $ in your code just wrap a function around it like so:

jQuery.noConflict()
(function($) {
  $("your element selector").whatever();
})(jQuery)

Additional benefits described in the Answers to What is the benefit of wrapping a jquery function in a closure?

Community
  • 1
  • 1
Richard Durr
  • 3,081
  • 3
  • 20
  • 26