jQuery Wordpress conflict

40 views
asked Apr 11, 2012 in General by validnet (1,140 points)
edited Apr 11, 2012 by necser
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 like 0 dislike
answered Apr 11, 2012 by RalphK (5,800 points)
Never use jQuery handy function $() in WordPress plugin. You have to use jQuery() or jQuery.noConflict() to work between jQuery and WordPress.
0 like 0 dislike
answered Apr 11, 2012 by SmartHost (9,060 points)
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');
});
...