0

I have an MVC project and in my View I'm trying to create a "Select All" and "Rest" button that will either check all or clear all RadioButtons on the page. I'm getting an error in the Dev Tools that says "Uncaught ReferenceError: $ is not defined". Just for testing purposes I'm first just trying to kick off an Alert but continue to get the error. I don't see what the problem would be.

Here is my button on the page:

<button type="button" id="btnReset" class="btn btn-default btn-sm">
    <span class="fa fa-refresh" aria-hidden="true"></span> Reset
</button>

This is the jQuery I have at the bottom of the page.

<script type="text/javascript">
  $(document).ready(function(){
      $("#btnReset").click(function () {
          alert("clicked");
        //$('input:radio').attr('checked',false);
        });
  });
</script
Caverman
  • 3,371
  • 9
  • 59
  • 115
  • is jQuery definitely included on the page? – martincarlin87 Oct 25 '17 at 16:21
  • Just to make sure.. You are including jQuery in the page? Add this to the head section: `` – blackandorangecat Oct 25 '17 at 16:21
  • 1
    Post the line where you include jquery, 99% of this type of question about jquery being undefined is because jquery was not included properly – Huangism Oct 25 '17 at 16:22
  • That's a strong indication that the library you have tried to load has failed/doesn't exists or you have not tried to include the required library before running your script. – NewToJS Oct 25 '17 at 16:23
  • Thanks. This is a project I'm just taking over and from what I can see in the _Layout page it has the jQuery bundle to include jQuery but I guess I'll have to try to figure out why it's not loading. jQuery not being loaded seems logical for the error message. – Caverman Oct 25 '17 at 16:30
  • Also, you need to have the jQuery script before your script/code – GramThanos Oct 25 '17 at 16:31
  • Thanks for all of the comments, it did lead me to looking at this closer. The issue was ultimately that my script was running before jQuery. In the _Layout View there is a "@RenderSection("scripts")". I had to wrap the – Caverman Oct 25 '17 at 16:40

0 Answers0