WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding jQuery to Child Theme (2 posts)

  1. Dinesh
    Member
    Posted 1 year ago #

    I've done some hardcore php programming in the past. Played around with wordpress about a year ago and now playing around with it again.

    I am using WordPress 3.5 and am writing a child theme based on the twenty twelve theme. I've added a JavaScript file with the following code in functions.php

    function my_scripts(){
    
        wp_register_script("myscript", WP_CONTENT_URL . "/themes/my_child_theme/js/my-script.js");
    
        wp_enqueue_script("myscript");
    }
    
    add_action("wp_enqueue_scripts", "my_scripts");

    The .js script file is being loaded properly (I checked the "View Source Code" from mozilla), but the script doesn't seem to be doing anything. I've cracked my head over the last 3 days trying different variations of my script from a simple alert("Hello World") to slightly more complex document ready functions... but nothing seems to work.

    Been reading different variations of how to get script working on the internet... but nothing works!!!

    ----------------------------------------
    $(document).ready(function(){
        alert("Hello World");
    });
    ----------------------------------------
    jQuery(document).ready(function(){
        alert("Hello World");
    });
    ----------------------------------------
    (function($) {
        $(document).ready(function(){
            alert("Hello World");
        });
    })(jQuery);
    ----------------------------------------

    This is what my "my-script.js" looks like now:-

    ----------------------------------------
    (function(a){
    	function b(){
    		alert("Hello");
    	}
    	a(document).ready(function(){
    		a("#my_input").val("").keyup(b);
    	})
    })(jQuery);
    ----------------------------------------

    Any help provided is much appreciated.

    Thank you and regards,
    Dinesh

  2. Dinesh
    Member
    Posted 1 year ago #

    I call myself a hardcore php programmer!!! I forgot to include the actual jquery script. Sorry. It's working now!

    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic