Bat_Georgi
Bat_Georgi

Reputation: 21

jQuery can't find element in ASP.NET MVC Project

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

Answers (1)

Only Bolivian Here
Only Bolivian Here

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

Related Questions