Alex Alex - 7 months ago 15
Javascript Question

How to use id-name on keydown event?

I have a js code like this:

$(document).on('keydown', function(e) {
if (e.keyCode === 13) {


Above code works as well (for all textarea(s)). Now I want to devote the above code for all textarea's except this
id: #idname





I tried this:

$(document).on('keydown', 'textarea:not(#idname)', function(e) {
if (e.keyCode === 13) {


But this code doesn't work, How can I fix it?

Answer
$(document).on('keydown', function(e) {
    if(document.activeElement === $("#idname")[0]) return;
    if (e.keyCode === 13) {
Comments