I want to limit execution with hit enter only to specific div, not on whole page so that this enter key not impact to divs outside this #targer-wrapper but code below with checking div length didn't works:
if ($('#targer-wrapper').length) {
$('#targer-wrapper').on('keydown', '#children-input', function (e) {
value = $('input#children-input').val();
if (value.length >= 3) {
functionName();
} else if (e.which === 13 || e.keyCode === 13) {
functionName();
}
});
}
Thanks for help and suggestion
As you want to fire a Function on a specific element, you should select that element ( in your case, #targer-wrapper ) and set the eventListener on it:
You should use a direct eventListener rather than relying on event propagation.