Grow your CSS skills. Land your dream job.

Wrong js in WordPress

  • # March 20, 2013 at 12:30 pm

    Hi.
    I have problem with simple jquery function. Everything seems fine to me but it says:
    Uncaught SyntaxError: Unexpected identifier on line 8.
    Here is my code:

    jQuery.noConflict();
    /*Change images src on hover*/
    jQuery(document).ready(function($) {
    $(‘.bnt1Program a’).bind(‘mouseover’, function() {
    $(‘img#programHeaderBnt1′).attr(“src”, “logo.png”);
    }

    $(‘.bnt2Program a’).bind(‘mouseover’, function() {
    $(‘img#programHeaderBnt2′).attr(“src”, “logo2.png”);
    }

    $(‘.bntWProgram a’).bind(‘mouseover’, function() {
    $(‘img#programHeaderBntW’).attr(“src”, “logo3.png”);
    }
    }

    And in functions php i used:

    function my_load_scripts() {
    if (!is_admin()) {
    wp_register_script(‘changeHImag’, ‘/wp-content/themes/bnt/js/chHIm.js’);
    wp_enqueue_script(‘changeHImag’,’/wp-content/themes/bnt/js/chHIm.js’, array(‘jquery’));
    }
    }
    add_action( ‘wp_enqueue_scripts’, ‘my_load_scripts’ );

    What’s wrong ?
    Thank you in advance.

    # March 20, 2013 at 12:34 pm

    Do you really need `jQuery.noConflict();`?

    Add closing brackets for your bind functions ( `);` after each `}` )

    # March 20, 2013 at 12:45 pm

    Thank you.
    But now it’s says:
    Uncaught SyntaxError: Unexpected end of input .

    # March 20, 2013 at 12:49 pm

    After each of your binds, you’re only closing it with `}`. It needs to be `});`.

    # March 20, 2013 at 12:49 pm

    Same thing at the very end of your document ready.

    # March 20, 2013 at 12:57 pm

    Thank you :)

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".