1

This is my current, i want to change .live but .on is not working..

$('#SearchString').live('keydown',function(e) {
if (e.which == 13) {
    if (!$("#SearchString").val()) {
        alert("Inget postnummer eller ort angiven!");
        return false;
    }
}
});




 $('#SearchString').on('keydown',function(e) {
if (e.which == 13) {
    if (!$("#SearchString").val()) {
        alert("Inget postnummer eller ort angiven!");
        return false;
    }
}
});

This is the ON version

1 Answers1

3

In event delegation model of on() the target element selector is passed as the second argument to the on() method.

$(document).on('keydown', '#SearchString', function(e){
    if (e.which == 13) {
        if (!$("#SearchString").val()) {
            alert("Inget postnummer eller ort angiven!");
            return false;
        }
    }
})
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531