jQuery's no-conflict mode: yet another reason why it's the best
It took me a bit to find out why jQuery (now bundled with WordPress) was not working as I expected inside of the WP admin area. The script was being called, but my code like $("#foo") was not working. I really had no clue where to begin, since it still has all those old JS libraries/frameworks being called as well. It was due to Prototype being packaged with it and conflicting with the "$" shortcut.
Long story short, jQuery already planned for library conflicts and has a quick solution. The no-conflict mode allows you to define your own shortcut, and of course it works like a charm.
It's easy to do - just put this line in your code somewhere:
var J = jQuery.noConflict();
Now $("#foo") will be J("#foo") and it will not conflict with any other libraries that may be installed. I hope WP gets rid of all the other stuff and goes with pure jQuery and plugins soon enough though
excellent solution! worked like a charm! thank you!
Can I see your html, I don't understand where to put it. I am not to good with javascript.
Thanks
This also fixes the issue between lightbox2 and jQuery Multi Level CSS Menu #2...
Genious
THIS ROCKS! I been starring at my wordpress theme code for days.. I know it must be some conflict going on there.. and YOU .. YOU GAVE ME THE ANSWER! this is so awesome!
Sorry for being stupid. But I tried the noConflict() function. I placed it RIGHT AFTER jQuery.js is called, but BEFORE prototype is called. In between these two, I had other UI libraries being called as well. I assigned jQuery to new var $j, and I changed the call in my function (which is called after all the libraries) to refer to $j instead of $, it still doesn't work.
It looks like my UI libraries functions are now broken (from the error I am getting like "the.style" is null or not an object).
Can you please help?? Thanks so much in advance!
Honestly, I don't think I can help. I got lucky with this a while ago, and I simply done have the mental patience to try and work with it again... sorry
Thanks for this great solution.
But I have one problem with this.
I am using "jquery.blockUI.js" also.
I have put "var JQ = jQuery.noConflict();"
I changed all "$" with "JQ" in "jquery.blockUI.js"
but as I use "JQ.blockUI({.......});", I am getting the javascript error that "JQ.blockUI is not a function"...
So what should I do to make working ?
I don't know... I'd try the author of blockUI
okay, so i'm running proto/jquery together and it works fine on Safari and FF with out having to add jQuery.noConflict(); but it won't work on IE6/7... separately both scripts work fine in IE6/7. When I open my page in IE6/7 the jquey.js works but the proto/scriptac opens my lightbox in a new page... I tried the jQuery.noConflict(); fix with no results. I'm not sure if i'm implementing it properly...i'm new to this and eager to learn. I also tried moving jquery script above the proto script recommended on other sites and nothing.
here is the code i need help with. help me obe wan you're my only hope...
here is the code i need help with.
var GB_ANIMATION = true;
$(document).ready(function(){
$("a.greybox").click(function(){
var t = this.title || $(this).text() || this.href;
GB_show(t,this.href,420,450); return false;
});
});
sorry. here is the entire code
okay, so i'm running proto/jquery together and it works fine on Safari and FF with out having to add jQuery.noConflict(); but it won't work on IE6/7... separately both scripts work fine in IE6/7. When I open my page in IE6/7 the jquey.js works but the proto/scriptac opens my lightbox in a new page... I tried the jQuery.noConflict(); fix with no results. I'm not sure if i'm implementing it properly...i'm new to this and eager to learn. I also tried moving jquery script above the proto script recommended on other sites and nothing.
here is the code i need help with. help me obe wan you're my only hope...
here is the code i need help with.
var GB_ANIMATION = true;
$(document).ready(function(){
$("a.greybox").click(function(){
var t = this.title || $(this).text() || this.href;
GB_show(t,this.href,420,450); return false;
});
});
var GB_ANIMATION = true;
$(document).ready(function(){
$("a.greybox").click(function(){
var t = this.title || $(this).text() || this.href;
GB_show(t,this.href,420,450); return false;
});
});
Sorry dude, but I've got too much on my plate right now to be able to help. I haven't touched this code in a long time.
You should try #jQuery on irc.freenode.net ...
Worked like a charm with mootools and jquery conflict in joomla. I couldn't get virtuemart working, but by simply adding your code "var J = jQuery.noConflict();" all problems disappeared! Many Thanks
i've benn sitting in front of this problem for hours. i knew that there was a conflict, but i couldnt get it to work, since I read this article.
thank you very much
Thank you very much!!! I have searched a lot I finally found this text
) Great idea! Thanks..
var J = jQuery.noConflict();
at the top of your Jquery function;
then replace all instances of $ with J inside your jQuery function!
Worked perfectly!
@Anonymous
As explained in this post you don't need to replace all your "$" with "J". All you have to do is to use this javascript workaround:
function($){
// ur code that uses $
$('#myId').show();
}(jQuery);
Thanx so much!!!!
worked like a charm!
Where do I place the jquery code? Im have a issue with the jquery in featured content glider. Its conflicting with smash galleries and lightbox-plus, any help please?
I been trying to find the anwser for weeks.
Look a couple posts up. That's probably the best answer I'd give.
great, it works.
When i combined a modal dialog box using facebox.js and a slidehow in a page, it did not work.
i put this like the script above:
.......*some jQuery*
.......
var J = jQuery.noConflict();
/*** and then i changed all $ to J in function () ***/
accomplished
thanks
I have the same problem as Dhaval Patel
I am using jQuery.js and dataTable.jQuery.js which conflicts with protoType.js
the noConflict() works perfect for jQuery, but the dataTable.jQuery.js says function not found and tries to look into protoType.js....
Any idea to get arround this.. ??
I can't promise i can help but if you pastebin'ed the source code to dataTable file (which should be the place you need to make a change, not in jQuery.js) perhaps someone can help out or I can find the culprit quick. Javascript gives me a headache. Hence why I love jQuery
@mike
Put it at the top of you .js file and then replace any '$' you've used. for example:
$(function () {
// your code here
}
becomes:
var J = jQuery.noConflict();
J(function () {
// your code here
}
(Thanks for the post!)
Waouhhh!! What's a wonderfull topic, there was a long time I was looking for this solution !!
Thanks, Thanks and Thanks again!!
Arno
http://htmlerror-info.blogspot.com/2009/12/prototypejs-in-li.....ckbox.html
JQuery continaully saves my sanity from javascript embolisms! Thanks for posting this out there.
Great posting. Thank you so much!!! It works great!!
Worked perfectly!
Thank you...
Hello, when I use this solution IE 8 crashes. The other browser work fine.
Great, I had conflict between two plugins in Wordpress (Featured Content Galary and WPReviewengine) and put your line in jquery.js. SOLVED. thx
u r the real genious man.
Hey,
Thanks for this solution, I wrote a small script based on the jTwitter library to fetch my latest tweets and it was conflicting with LightBox, but this solved it
Cheers!