php - wordpress - jQuery doesn't work in plug in, but works everywhere else? -


sorry easy question, (hey, easy rep!) i'm new php of 1 day. have create wordpress plugin/widget out of necessity. have en queued jquery in header:

  `<?php wp_enqueue_script("jquery"); ?>` 

and created class intended clicked in plugin.

  jquery('.court').click(function () {       alert(jquery(this).attr('id'));    }); 

simple stuff , works if place code within footer (which has nothing else in jq). not work if it's inside plugin. javascript alert('boom'); work in plugin.

what missing in order use jquery within plugin? don't want put in footer since won't packaged there.

i have create wordpress plugin/widget out of necessity. writing plugin scratch? if so; try adding code below anywhere in plugin's main file:

    <?php         function mypluginscripts() {             wp_enqueue_script( 'jquery-my-plugin', get_site_url() . "/wp-includes/js/jquery/jquery.js", array(), '');              // in function, can add other js files              // uncomment line below & change values if need             // wp_enqueue_script( 'my-plg-js', 'path/to/my-plg.js', array('jquery'), '');        }         add_action('wp_enqueue_scripts', 'mypluginscripts'); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -