tags:

views:

163

answers:

1

I cannot understand why the code below is giving me this error in firebug

$ is not defined

Can someone explain?

<script type="text/javascript" >
 $(document).ready(function(){
  setTimeout2(function(){
  $("#errormsg4").fadeOut("slow", function () {
  $("#errormsg4").remove();
      }); }, 5000);
 });
</script>

<div id="errormsg4">test</div>
+3  A: 

As you said $ is not defined that means you have not given the reference of jquery script file before using your script code. Also I think you had mistyped setTimeout2,it would have been setTimeout.Try below code

<html>
<head>
    <title></title>    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>    
</head>
<body>
    <div id="errormsg4">
        test</div>
</body>    
<script type="text/javascript">

    $(document).ready(function()
    {
        setTimeout(function()
        {
            $("#errormsg4").fadeOut("slow", function()
            {
                $("#errormsg4").remove();
            });
        }, 5000);
    });
</script>

</html>
Raghav Khunger
Ok thanks that was my problem then, the naming of setTimeout2 I didnt realize setTimeout was a predefined function of jquery, I had copied this code from elsewhere, I spent the night reading up on jquery it all makes better sense now
jasondavis
@jasondavis - setTimeout isn't jQuery, it's JavaScript. jQuery is basically a bunch of JavaScript functions. Please read some more :)
Kobi