find and solve || findandsolve.com
Please wait.....

Uncaught ReferenceError: $ is not defined

I have create simple jquery function as a click event.

<script type="text/javascript">
    $(function() {
        $('#btlPost').click(function() {
            alert("hwllo word");
        });
    });
</script>

and i have added  jquery reference in my master layout.


Answer


Option 1.

Some case therefore this types of error has been occure like as givel below.

  1. If your Jquery library file is not being properly loaded into your scripting page.
  2. You have a botched version of jQuery. This could happen because someone edited the core file, or a plugin may have overwritten the $ variable.
  3. Page is fully loaded and call JavaScript function after that JQuery is fully loaded in the page.
  4. In .NET Core,JavaScript function is not create under script section like as given below.
@section Scripts{
<script type="text/javascript">
    $(function() {
        $('#btlPost').click(function() {
            alert("hwllo word");
        });
    });
</script>
}

First of all, ensure, what script is call properly, it should looks like

<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" type="text/javascript"></script>


Option 2.

If you create view page in .net core like index.cshtml(razor syntax)

@section Scripts 
{     <script type="text/javascript">
      $(document).ready(function () {
        // Do your custom javascript for this view here. Will be run after
        // loading all the other scripts.
      });
    </script>
}


Option 3.

If the jQuery plugin call is next to the </body>, and your script is loaded before that, you should make your code run after window.onload event, like this:

window.onload = function() {
  //your query/code here
}


Mahira  khanna

Mahira khanna

I have the skills you need for you company blog, website, or other content materials

Comments



Report Response