-4

I have the following very simple code:

<script type='text/javascript'>
  $(document).ready(function() {
    alert('ghg');
  });
</script>

This code does not work, since the alert is not displayed.

However, the following code shows the alert:

<script type='text/javascript'>
  alert('ghg');
</script>

What it is the problem?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Irving
  • 1
  • 1
  • 2
    That means jQuery isn't loaded as of when you run that code, or it's loaded by it doesn't have control of the `$` variable (in that case, try `jQuery(document).ready`...). Are you including jQuery on the page before that code? When you look in the web console, do you see any errors? – T.J. Crowder May 12 '19 at 17:09
  • yes I got errors Uncaught ReferenceError: jQuery is not defined at jquery-ui.min.js:6 at jquery-ui.min.js:6 (anonymous) @ jquery-ui.min.js:6 (anonymous) @ jquery-ui.min.js:6 jquery- – Irving May 12 '19 at 17:13
  • You've included jQuery UI, but not jQuery. They're separate scripts. – T.J. Crowder May 12 '19 at 17:15
  • T.J. Crowder that was the problem jquery.js was missing thanks :) – Irving May 12 '19 at 17:26

1 Answers1

0

You must add Jquery plugin in your code.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type='text/javascript'>

  $(document).ready(function() {
    alert('ghg');
  });
</script>