0

Hi I spend hours to figure out the problem why my own javascript doesn't work even in html output it seems loaded. I want to share it.

with these line of code

wp_enqueue_script( 'myscrip', plugin_dir_url( __FILE__ ) . 'js/test.js',array('jquery'),NULL);

it works properly problem was in my script file. I used jQuery "$" notation in my script and when I changed it to "$"->"jQuery" all worked normmaly.

1 Answer 1

2

You can add jQuery like this:

wp_enqueue_script('jquery');

then register your own JavaScript like this:

wp_register_script('myplugin', plugins_url('/js/myplugin.js', __FILE__), array('jquery'));
wp_enqueue_script('myplugin');

You can also add $ = jQuery.noConflict(); before the ready function to make use of the "$" notation.

E.g.

$ = jQuery.noConflict();

$(document).ready(
function() {
        $('#link').click(function(){alert('');});
    }
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.