Loading
Loading

Reputation: 1100

How to install & use jquery in asp.net mvc

What i did so far:

Step1: installed "jQuery.UI.Combined" via NuGet
Step2: In my Razorpage I include this code:

<script src="~/lib/jquery/dist/jquery.js" type="text/javascript">
    $(document).ready(function () {
        $("#test").click(function () {
            $("#NavBar_OptionPanel").toggle();
        });
    });
</script>

Step3: This is my Button:

<a id="test">Settings</a>

Step4: This is the Panel i want to toggle on/off:

<div id="NavBar_OptionPanel">
    <label>Options</label>
</div>

What i expected: When clicking on an element with id="test", all elements with id="NavBar_OptionPanel" should toggle on/off

But nothing is happening. So i guess there could be two problems:

  1. The installation of jQuery is wrong/a step missing
  2. The usage of jQuery is wrong

Can you help me?

Upvotes: 0

Views: 2360

Answers (1)

LiefdeWen
LiefdeWen

Reputation: 586

You have your code inside your script tag including jquery, change it to this:

<script src="~/lib/jquery/dist/jquery.js" type="text/javascript"></script>
<script>
    $(document).ready(function () {
        $("#test").click(function () {
            $("#NavBar_OptionPanel").toggle();
        });
    });
</script>

Upvotes: 4

Related Questions