Uncaught ReferenceError: 'functionName' not defined

javascript, jquery

Solution

Move your `functionName()` out side of `$(document).ready(function(){`

function functionName() { ....... }

$(document).ready(function(){
    $('.current').click(function(event){
        functionName();
    });
});

Also, you need to use `.` to target element by class or `#` to target element by `id`

So `$('.current')` will select any element with `class="current"` and `$('#current')` will select an element with `id="current"`

Last note is to update your jQuery version since `1.3.1` is extremely outdated already and it lacks of many helpful and important features which is supported by later versions.

Problem

So I have checked my script tags in my .jsp file: ``` <script type="text/javascript" src="javascript/jquery-1.3.1.min.js"></script> <script language="JavaScript" > "some content here ...." </script> ``` and below in the same .jsp file I have a tag: ``` <body BGCOLOR="white" text="black" link="blue" vlink="red" onLoad="functionName();enableBackButton();"> ``` However, in my JavaScript file I have: ``` $(document).ready(function(){ $('current').click(function(event){ function functionName() { ....... } ``` Somehow I keep getting an error in my Chrome console stating: Uncaught ReferenceError: functionName is not defined

Original source

Related problems