Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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" ...

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

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top