How To Fix jQuery Conflict

I am not yet become jQuery expert, but I had learned a lot from this code, my jQuery Guru told me about this code very well. So when I got some problem I will go to him 😀 and almost all my problem will be solved, except this one 😀

jQuery-No-Conflict-Hack-and-Tips
jQuery-No-Conflict-Hack-and-Tips

Why he can’t solved this? It’s because last night he can’t be focused on my problem, he still have some jobs at the office, so I am baking you pardon if I was disturbing you my guru 😉 So the next answer in my WordPress problem is Uncle Google of course 😀 .

After look around for a while and analyzing my jQuery code was conflict with other variable code. So I began to explored how to fix it and what should I do, until I got the easy solutions how to fixed the jQuery conflict, all that I need to do just fix the variable, because it need a unique variable to make this jQuery code working.

Here’s a jQuery Code Example

My Original jQuery is like this

[sourcecode language=”javascript”]<script type="text/javascript">
$(document).ready(function() {
$("ul.dropdown-horizontal ul li:has(ul)").addClass("dir");
});

$(function() {
$(‘#slideshow’).cycle({
fx:      ‘scrollDown’,
timeout:  5000,
pause:   1,
speedIn:  2000,
speedOut: 500,
easeIn:  ‘bounceout’,
easeOut: ‘backin’,
delay:   -2000
});
});
</script>[/sourcecode]

This code running perfect, if there are no other jQuery code. But it will be got an  error if you has another jQuery code. So to handle this problem, you need to has a unique variable. I mean mostly $ (variables) is the default code of jQuery, so we must to create unique variable

This is an example of the code after I make unique variables,

[sourcecode language=”javascript”]<script type="text/javascript">
var $jx = jQuery.noConflict();

$jx(document).ready(function() {
$jx("ul.dropdown-horizontal ul li:has(ul)").addClass("dir");
});

$jx(function() {
$jx(‘#slideshow’).cycle({
fx:      ‘scrollDown’,
timeout:  5000,
pause:   1,
speedIn:  2000,
speedOut: 500,
easeIn:  ‘bounceout’,
easeOut: ‘backin’,
delay:   -2000
});
});
</script>[/sourcecode]

When you check the second code, you will found a unique variable $jx as a new variable and replace default $.

More reference about this problem, you can check on this jQuery Docs. That’s all, I hope you understand with this post  and Have A nice day 😉

27 Comments

  1. Im having a jquery conflict on my feature content glider! The glider jquery is conflicting with photosmash galleries and lightbox-pro in wordpress.mu root page. can you help me?

  2. Where do I place the code? In the jquery wpmu libraries or the featured content glider jquery? It doesnt refer to drop this code anywhere.

    Thanks for the reply.

  3. Where do I place the code? In the jquery wpmu libraries or the featured content glider jquery? It doesnt refer to drop this code anywhere.

    Thanks for the reply Jauhari!

  4. Some interesting points, but I’m not sure this really looks at the history of the issue. How has this come about? And where do we go from here? Look forward to you addressing this in future posts.

  5. Hi Jauhari, you put me on track but i solved my problem between two plugins (WPreviewengine and Featured Content Gallery) in WordPress by putting in the following line in jquery.js in wpreviewengine.

    var J = jQuery.noConflict();

    It does the same! but in one comment.

  6. hello sir,

    I’m new with wordpress and i have been doing some personal projects to improve my experience with it. One of my major resources if i struggle with wordpress is through forums and research and so far everything was going well until now. I added a plugin Featured COntent Gallery from iplexus to add some effects on my website. The current theme that i am using has jquery and slider javascripts. I found out that featured content gallery uses Mootool and has some compatibility issues with jquery hence my Featured content gallery does not work. Found a solution though which is to use a code jquery.noConflict() to solve the problem. But when i insert the code and got the Featured Content Gallery to work, the tab slider now does not work…But when i take out the jquery.noConflict() function in my jquery script, the Featured COntent Gallery does not work and the slider this time works. Can u please take a look at my site to see what is happening? Still a newbie at this but im doing my best to learn.

  7. Mohon bantuannya dong…
    Sy pake plugin FCG pada theme channel, gambar gak muncul dan error yang muncul di Error Console firefox sbb:
    $$.shared is undefined
    http://…./mootools.v1.11.js
    thanks

  8. saya baru saja mengalami hal seperti ini… tadinya saya kira pake JQuery.noConflict() bisa menyelesaikan konflik antara 2 plugin jquery yang saya pakai… ternyata enggak _~_

    dan ternyata ini dipakai untuk mengatasi konflik jquery dengan js library lainnya… _~_ anyway… thx buat infonya pak..

  9. Hi Jauhari,

    Thanks,
    You have put me on track with my jquery-conflict, thanks so much for taking the time to write this blog post, 2 years old and it is still helping people out!

    Sandy.

Leave a Reply

Your email address will not be published. Required fields are marked *