I was told that jquery was automagically included in wordpress from the get go, but I went ahead and included jquery in my functions.php. I'm trying to do a simple script that scrolls down to a div#id when a link is clicked.
I created this script:
jQuery(document).ready(function($) {
jQuery("#view-visibility").click(function() {
jQuery('html, body').animate({
scrollTop: jQuery("#visibility").offset().top
}, 2000);
});
)};
I put the script in my own file, script.js, and added it to the functions.php:
`
function theme_js() {
//parameters: 1.handle, 2.path, 3.array of dependents, 4.version specification, 5.load in footer? true or false
wp_enqueue_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', '', '3.1.1', true );
wp_enqueue_script( 'bootstrap_js', 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/js/bootstrap.min.js', array('jquery'), '', true );
wp_enqueue_script( 'my_js', get_template_directory_uri() . '/script.js', array('jquery'), '', true );
}
add_action( 'wp_enqueue_scripts', 'theme_js' );`
I still can't get it to work... I don't know what the deal is!! Should I be loading jquery in the head or before the body?
Link to my site http://jakeford.io/pwi-project
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments