Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14217 reviews 1686 hosting providers

Questions & Answers

jQuery Wordpress conflict

Apr 11, 2012 by validnet
Hi all,
I have a problrm running any jQuery on my  WordPress plug-in writing? Even running a simple jQuery effect like following doesn’t work.
$(document).ready(function(){
  alert('test');
});
No alert message popup. The same code is working normally  in single HTML page.
Does anyone know why is this happening and how can I solve it? Please help

2 Answers

0 votes
Apr 11, 2012 by RalphK
Never use jQuery handy function $() in WordPress plugin. You have to use jQuery() or jQuery.noConflict() to work between jQuery and WordPress.
0 votes
Apr 11, 2012 by SmartHost
In WordPress, $( ) syntax is always used by other scripting library, causing a conflict issue and failing to call the jQuery function. You should use jQuery() instead
jQuery(document).ready(function(){
  alert('test');
});
you can also use noConflict() …
$j=jQuery.noConflict();
 
// Use jQuery via $j(...)
$j(document).ready(function(){
  alert('test');
});