Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Wrong js in WordPress

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #43528
    bastunqk
    Participant

    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.

    #128994
    CrocoDillon
    Participant

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

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

    #128998
    bastunqk
    Participant

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

    #129000
    TheDoc
    Member

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

    #129001
    TheDoc
    Member

    Same thing at the very end of your document ready.

    #129003
    bastunqk
    Participant

    Thank you :)

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.