Question

Why ReferenceError: $ is not defined ?

<script src="LAB.js"></script>
            <script>
     $LAB.script("jquery/jquery.js")
    </script>

     </body>

    <p><?php echo mt_rand(89,161464) ?></p>

    <script>
//Uncaught ReferenceError: $ is not defined 

$(document).ready(function(){
    console.log('reddy');
    $("p").css('color','red');
    })  
</script>

But work:

   window.onload=function(){
        $("p").css('color','red');
        }

2.item1.js

 var interface={name:'interface'};

item2.js

interface.hu={name:'int'};

$LAB.script("item2.js").wait();
$LAB.script("item1.js");

//Uncaught ReferenceError: interface is not defined Help

Was it helpful?

Solution

try :

$LAB.script("jquery/jquery.js").wait(function () {
   if( window.jQuery ) { //is jquery loaded
       $("p").css('color','red'); 
   }
});

OR

$LAB.script("jquery/jquery.js").wait(function () {
   $(document).ready(function() {
       $("p").css('color','red'); 
   }
});

See more:: LABjs Doc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top