[ jQuery ON error. No error when using LIVE ]
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
Answer 1
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;
}
}
})