Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
jquery document with not selector

I have some search fields on a page. Upon pressing 'enter' anything in these fields will then get filtered on for a dataset that's displayed on a table.

$("document").on('keyup', (e) => {
    if (e.keyCode === 13) {
        searchAndDraw();
    }
});

My issue is that I have a table #myTable with some textareas in tds . Hitting 'enter' inside a textarea also triggers the search as the table is inside the document.

How can I apply this keyup event to the doc but exclude #myTable?

I tried $("document:not(#tliId)").on('keyup'... but that does not work.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can target it to use enter on the inputs and exclude textarea

$(document).on('keyup', ":input:not(textarea)", (e) => {
  if (e.key === "Enter") {
    console.log("Enter");
  }
});
label {
  display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label></label><input />
<label></label><textarea></textarea>
<label></label><textarea></textarea>
<label></label><input />

If you do not want the input to be in focus and they can hit enter anywhere you can check to see what the target is a textarea or not.

$(document).on('keyup', (e) => {
  if (e.key === "Enter" && !$(e.target).is('textarea')) {
    console.log("Enter");
  }
});
label {
  display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label></label><input />
<label></label><textarea></textarea>
<label></label><textarea></textarea>
<label></label><input />

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda