BlackFire27
BlackFire27

Reputation: 1550

jQuery doesnt work

This is my code:

    /// <reference path="../jquery-1.5.1.js" />
jQuery(function($){
    $(".deleteLink").click(function () {
        alert(1);
    });
});

$(".deleteLink").click(function () {


    alert(2);
});

This is my link:

<a class="deleteLink" data-ajax="true" data-ajax-mode="replace" data-ajax-update="#1" href="/Admin/Delete?deleteID=1&amp;unDelete=1" id="1">Delete</a>

In both cases whenever i press on the link no alert pops up.

Here are my links in the html file:

update:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>

<script src="@Url.Content("~/Scripts/AdminScript/AdminMenu.js")" type="text/javascript"></script> //External file where I execute my javascript/jquery code

Upvotes: 0

Views: 167

Answers (3)

Alexander St&#248;ver
Alexander St&#248;ver

Reputation: 645

Try this,

$(function(){
  $('.deleteLink').click(function(){
    alert('Hello world');
  });
});

Upvotes: 0

The Alpha
The Alpha

Reputation: 146191

$(document).ready(function(){
    $(".deleteLink").click(function () {
        alert(1);
        return false;
    });
});

Upvotes: 0

Marnix van Valen
Marnix van Valen

Reputation: 13673

The first part of your code uses an incorrect identifier to access jQuery. Try replacing $jQuery with either jQuery or $.

$(function(){
  $(".deleteLink").click(function () {
     alert(1);
  });
});

The second bit probably fails because you put it in the header. This code is executed immediately so if you put that in the header of the html the specified link doesn't exist yet.

Upvotes: 5

Related Questions