Reputation: 21
I am making a ASP.NET 3 MVC project, but it seems i can't make jQuery work properly.
In the view i have something like this:
<a id="login">lala</a>
Then in the .js file:
$("#login").click(function () {
alert("lal");
});
The alert doesn't show on the screen. I've added the reference of my custom .js file in _Layout and updated to the newest library, but whatever I do I can't find any element. What am I doing wrong here :s
Upvotes: 2
Views: 930
Reputation: 36753
Try:
$(document).ready(function(){
$("#login").click(function () {
alert("lal");
});
});
If this does solve your issue, google search for jquery document ready
and read up on the tons of material already written out there on what this does and why it exists.
Upvotes: 3