0

I am trying to use jQuery to scroll the div content vertically.

I have used the following line of code in function.php

add_action( 'wp_enquque_scripts', 'my_script_enqueue' );

function my_script_enqueue() {
    wp_enqueue_script( 'my-jquery', '/wordpress/wp-content/themes/MyTheme/js/jquery-1.9.0.js', array( 'jquery' ) );
}

then i have included a JS file in my PHP file as follows:

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/dw_scroll_c.js"></script>

In that JS file I am just displaying as alert as follows:

jQuery( document ).ready( function( $ ) {
    alert('hi');
});

But it's not working.

1

2 Answers 2

0
wp_enqueue_script( 'my-jquery', get_stylesheet_directory_uri() .'/js/jquery-1.9.0.js', array( 'jquery' ) );

check for jquery error also check with source code if file is being loaded or not. you must have included jquery library before including your js file.

0

Do not include js file in your php files, instead use the hook. below code will work for you. See the dependency parameter for wp_enqueue_script function. Your dw sroll file is dependent on jQuery.

add_action( 'wp_enquque_scripts', 'my_script_enqueue' );

function my_script_enqueue(){
wp_enqueue_script('dw_scroll_c','/js/dw_scroll_c.js',array( 'jquery' ));
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.