Tal Tal - 3 months ago 25
ASP.NET (C#) Question

Get button inside div javascript file

I am working on some MVC ASP .NET Project.

In my View folder i have a Dashoboard.cshtml file which include this part of code :

<div id="something">
<button type="button" class="btn btn-primary">Export To PDF</button>

I attached a script to the file :

<script src="~/Content/Scripts/js/dashboard.js"></script>

I created onClick function in the javascript file which will open another view file , but something is not working in my code.

#("#something .button").on('click', function () {

//Do something...


Can i get some help ? Thanks in advance!


Your jQuery class selector is wrong. And your'e using a # instead of $ for jQuery. Change the JS to the following.

$("#something .btn-primary").on('click', function () {

//Do something...