Reputation: 49
I'm trying to do the same event. "Click" to call the ajax, however now with keypress will put all the code and tell you where I think this error.
jquery:
$(document).ready(function () {
// Call Ajax Click <----- THIS WORK
$('.container-list-podcast').on('click', '.link-podcast', function (e) {
e.preventDefault();
$('.video').attr('src', this.href);
});
// Call Ajax Key Enter <----- THIS NOT WORK
$('.container-list-podcast').on('keypress == 13', '.selected', function (e) {
e.preventDefault();
$('.video').attr('src', this.href);
});
});
Upvotes: 1
Views: 1158
Reputation: 337580
Your event hook is incorrect as you have to check the key pressed by interrogating the event which raised the keypress
. Try this:
// Call Ajax Key Enter
$('.container-list-podcast').on('keypress', '.selected', function (e) {
e.preventDefault();
if (e.which == 13) { // keyCode 13 == Enter key
$('.video').attr('src', this.href);
}
});
Upvotes: 3