• I’m a total beginner to Javascript and have spent the last few days reading about it and its relation to WordPress. I’m now attempting to insert some simple Javascript/jQuery into my site and no surprise, it’s a total failure.

    First part, here is the code on jsfiddle: https://jsfiddle.net/hUxFX/
    I’m just trying to get a div to animate (float up and down) when you mouseover it. I must be missing something very obvious ??

    Next, I’m using functions.php in my child theme to add the script to the site, but when I look at my site’s source code I don’t see the script loaded, so I don’t think it’s working. I uploaded the aforementioned script file into my child theme’s js folder. Here is the code I have in my functions.php:

    <?php
    function ax_load_my_script() {
    	 wp_register_script(
    		'floating',
    		get_template_directory_uri() . '/js/floating.js',
    		array('jquery')
    		);
    
    		wp_enqueue_script( 'floating' );
    	};
    
    add_action( 'wp_enqueue_scripts', 'ax_load_my_script' );
    
    ?>

    I am… at a complete loss. A helping hand would be very appreciated!

    edit: ah and one more thing, my site https://www.axtran.com

Viewing 2 replies - 1 through 2 (of 2 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Your jQuery has syntax errors.
    This is how it should be https://jsfiddle.net/hUxFX/ – Actually not sure that saved – Here it is;

    $(document).ready(function () {
      $('#logo').hover(function () {
           $('#logo').animate({top:'+=20'}, 1000);
           $('#logo').animate({top:'-=20'}, 1000);
       });
    });

    Remember to check the browser’s console log when developing JavaScript.

    Thread Starter axtran

    (@axtran)

    Thanks again Andrew – I remember you helped me on these forums last time I had a problem. The script is working!

    The problem still remains as to getting it to load and execute on the site. Did I do something wrong in the functions.php or other steps leading up to it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help with simple JQuery and getting it on the site’ is closed to new replies.