Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(document).ready(function(){ Uncaught ReferenceError: $ is not defined

Tags:

Hi I am having a "Uncaught ReferenceError: $ is not defined" while using bellow codes

I am currently getting the following error in my log. I have been looking at the samples in the framework and I just can't seem to find where the error is. It's been over a decade since I have done any HTML or js and what I did back then was very basic stuff. Any help would be appreciated

<script type="text/javascript"> var sQuery = '<?php echo $sQuery; ?>';  $(document).ready(function(){     if($('input[name=sPattern]').val() == sQuery) {         $('input[name=sPattern]').css('color', 'gray');     }     $('input[name=sPattern]').click(function(){         if($('input[name=sPattern]').val() == sQuery) {             $('input[name=sPattern]').val('');             $('input[name=sPattern]').css('color', '');         }     });     $('input[name=sPattern]').blur(function(){         if($('input[name=sPattern]').val() == '') {             $('input[name=sPattern]').val(sQuery);             $('input[name=sPattern]').css('color', 'gray');         }     });     $('input[name=sPattern]').keypress(function(){         $('input[name=sPattern]').css('background','');     }) }); function doSearch() {     if($('input[name=sPattern]').val() == sQuery){         return false;     }     if($('input[name=sPattern]').val().length < 3) {         $('input[name=sPattern]').css('background', '#FFC6C6');         return false;     }     return true; } </script> 

enter image description here

like image 687
Monika Milosavich Avatar asked Jun 02 '12 18:06

Monika Milosavich


People also ask

How do I fix uncaught ReferenceError is not defined?

The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file has loaded. Therefore make sure that you're executing the jQuery code only after jQuery library file has finished loading.

Is not defined in $( document .ready function ()?

ready is not a function" error occurs for multiple reasons: Placing second set of parenthesis after the call to the ready() method. Loading the jQuery library after running your JavaScript code. Forgetting to load the jQuery library.

What does uncaught ReferenceError is not defined mean?

The JavaScript exception "variable is not defined" occurs when there is a non-existent variable referenced somewhere.

What does $( document .ready function () do?

$( document ). ready()A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ). ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.


1 Answers

It seems you don't import jquery. Those $ functions come with this non standard (but very useful) library.

Read the tutorial there : http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery It starts with how to import the library.

like image 78
Denys Séguret Avatar answered Sep 20 '22 04:09

Denys Séguret