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 :D and almost all my problem will be solved, except this one :D

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 :D . 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.

jquery-conflict

Here’s a sample.

My Original jQuery is like this

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

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,

<script type="text/javascript">
var $jx = jQuery.noConflict();

$j<img src='http://www.jauhari.net/engine/smilies/yahoo_angry.gif' alt='&#120;&#40;' class='wp-smiley' width='34' height='18' title='&#120;&#40;' />document).ready(function() {
$j<img src='http://www.jauhari.net/engine/smilies/yahoo_angry.gif' alt='&#120;&#40;' class='wp-smiley' width='34' height='18' title='&#120;&#40;' />"ul.dropdown-horizontal ul li:has(ul)").addClass("dir");
});

$j<img src='http://www.jauhari.net/engine/smilies/yahoo_angry.gif' alt='&#120;&#40;' class='wp-smiley' width='34' height='18' title='&#120;&#40;' />function() {
$j<img src='http://www.jauhari.net/engine/smilies/yahoo_angry.gif' alt='&#120;&#40;' class='wp-smiley' width='34' height='18' title='&#120;&#40;' />'#slideshow').cycle({
fx:      'scrollDown',
timeout:  5000,
pause:   1,
speedIn:  2000,
speedOut: 500,
easeIn:  'bounceout',
easeOut: 'backin',
delay:   -2000
});
});
</script>

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 ;)

About Jauhari

This is me Nurudin Jauhari. Just human like you, I come from Gunungkidul, small place at Yogyakarta, and Today I live at Malang I was born 30/04/1980 in Ponjong, small village in Gunungkidul, Almost my time in 1 - 15 Years stay at this Village. More
This entry was posted in How To and tagged , , , , , , , .
Bookmark the permalink.

17 Responses to How To Fix jQuery Conflict

  1. rahul says:

    i have use jquiry for tooltip but other functions r not working properly what is problem?

  2. Edward Ongo says:

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

  3. Pingback: vivek verma

  4. nuj says:

    thank you for this very good article. It really helps me fix my problem in wordpress.

  5. TR says:

    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

  6. Jonas says:

    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. Praveen says:

    I had the same experience with the conflict. We had the same problem in SharePoint too. So, please read the complete information here.
    http://praveenbattula.blogspot.com/2010/02/jquery-conflict-when-using-different.html

  8. Eep says:

    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.

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

  10. Pingback: jamesgallagher

  11. Pingback: James Gallagher

  12. Where shall I place the code? In the jquery wpmu folder or the theme jquery?

  13. Mitch says:

    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!

  14. Mitch says:

    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.

  15. 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?

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>