Mengenal jQuery

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

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

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

0

Comments

27 tanggapan untuk “How To Fix jQuery Conflict”

  1. Avatar own a condo or a house

    I love this band so much. Such beautifully ugly music.

    my blog – own a condo or a house

  2. How To Fix jQuery Conflict – http://is.gd/hoSyBR (via @JauhariNET)

  3. Avatar Adi

    Thanks! it’s work fine!!!!!

  4. […] There are some other methods like using the jQuery.noConflict() function to avoid conflicts in jQuery. […]

  5. Avatar yinka

    I am having similar problems and have tired everything but it is still not working.

  6. Avatar Sandys iPhone

    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.

  7. Avatar Niraj Dubey
    Niraj Dubey

    its working fine.

  8. Avatar siirt

    bisa menyelesaikan konflik antara 2 plugin jquery yang saya pakai
    Thank ytou

  9. Avatar KMX

    Thanks! it’s work fine.

  10. Avatar rahul
    rahul

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

  11. Avatar Edward Ongo

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

  12. How To Fix jQuery Conflict / JAUHARI: http://bit.ly/dhFIbr via @addthis

  13. Avatar nuj

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

  14. Avatar TR

    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

  15. Avatar Jonas

    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.

  16. Avatar Praveen

    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

  17. Avatar Eep

    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.

  18. Avatar Convicted Insurance

    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.

  19. jamesgallagher

    hmm … looks like themes with custom jQuery stuff don't play nice with WP2.9 – http://twurl.nl/apbt2t is what you need to know

  20. hmm … looks like themes with custom jQuery stuff don't play nice with WP2.9 – http://twurl.nl/apbt2t is what you need to know

  21. Avatar MItchell Medina

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

  22. Avatar Mitch

    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!

  23. Avatar Mitch

    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.

  24. Avatar Mitchell Medina

    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?

    1. Avatar Jauhari

      Try my solutions, did it fix your problem?

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Situs ini menggunakan Akismet untuk mengurangi spam. Pelajari bagaimana data komentar Anda diproses.