Tal Tal - 1 month ago 5
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>
</div>





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!

Answer

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...

})
Comments