Reputation: 35
I've been trying to add my custom jQuery script to wordpress, the script code and all is working on jsfiddle when I choose the jquery library, but when I'm trying to add it on wordpress it is not working. Here's how added the wp enqueue code:
function cb_scroller() {
//wp_enqueue_script('jquery');
wp_register_script( 'scroller', get_template_directory_uri() . '/js/scroller.js', array('jquery'),'',true );
wp_enqueue_script( 'scroller' );
}
add_action( 'wp_enqueue_scripts', 'cb_scroller' );
So what may be the problem? here's the jsfiddle attempt: https://jsfiddle.net/naimelhajj/q4bdfcwb/ (disregard the styling, I've imported the css and js as "external resources")
Upvotes: 0
Views: 76
Reputation: 318182
This is your script (which you should have posted in the question)
$(document).ready(function(){
$(".arrow-left").click(function(){
$(".site-main-gluten").animate({scrollLeft: "-="+100});
});
$(".arrow-right").click(function(){
$(".site-main-gluten").animate({scrollLeft: "+="+100});
});
});
Wordpress is in no-conflict mode by default, which means $
is not defined, it has to be
jQuery(document).ready(function($){
$(".arrow-left").click(function(){
$(".site-main-gluten").animate({scrollLeft: "-="+100});
});
$(".arrow-right").click(function(){
$(".site-main-gluten").animate({scrollLeft: "+="+100});
});
});
Upvotes: 2