3

The Jquery is not working with wordpress . its throws $ is undefined .

Code :

$('.action').on("change",function(e){
// my code
})
kasper chexonz
  • 541
  • 3
  • 12
  • 1
    try `jQuery('.action')` instead. \ – rrk Sep 18 '15 at 06:36
  • `$` is just an alias, there are other libraries such as `prototype` which uses the same alias, which causes conflicts with jQuery. If that is not the case, jQuery might not be included, or the jQuery object is assigned to some other variable, using **`noConflict(true)`** method. – rrk Sep 18 '15 at 06:38
  • Have you imported jQuery into your code? that is what the $ is. Just add `` in your html before your other JS executes. – winhowes Sep 18 '15 at 06:38

3 Answers3

5

The Wordpress Already Have Inbuild Jquery method so .

Try This . The Function Change The All $ to jquery and Working Fine .

(function($){ // use it as $
   $(document).ready(function(){ // make sure DOM is ready
      $('.action').on("change",function(e){ // bind the change event 
        // my code
      });
   });
})(jQuery); // pass jQuery in the IIFE

No Need To Add Jquery Library. As wordpress bundles with jQuery internally but uses jQuery keyword instead of its alias $.

Jai
  • 74,255
  • 12
  • 74
  • 103
codeBloger
  • 217
  • 2
  • 15
3

Use

 wp_enqueue_script(
        'my_voter_script',
        plugins_url( '/js/main.js' , __FILE__ ),
        array( 'jquery' )
    );

On Plugin Init Page To load External JS file

0

In Wordpress it includes the jquery. Try to replace all $ with jQuery and check. May be after replace $ with jQuery all working fine.

Kausha Mehta
  • 2,828
  • 2
  • 20
  • 31