Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: 'functionName' not defined

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

like image 517
Arty Avatar asked Feb 24 '14 16:02

Arty


1 Answers

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.

like image 156
Felix Avatar answered Oct 07 '22 05:10

Felix