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

390
Visualizações
JavaScript .focus() function not working in a text field

I'm trying to use .focus() on the following form field without success. The tabindex of the div this element is in is 0.

<input class="form-control ng-pristine ng-valid ng-empty ng-touched" id="accessionNumber" type="text" name="filter.accessionNumber" ng-model="selectFields.accessionNumber" style="">

I'm using the following:

document.getElementsByName("filter.accessionNumber")[0].focus()

I've also tried document.getElementById using the "accessionNumber" ID as well as the .click() function instead of the .focus() function but none have worked so far

Thanks!

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

0

Short answer: Maybe have a look at this post

Longer answer: Since you are using Angular you should use the features of the framework that enable this: ViewChild

Steps to make it work:

  1. In your component create a variable with the ViewChild annotation
  2. Mark the element with the ViewChild id in the Components Template
  3. Access your element in ngAfterViewInitlike
this.myElement.nativeElement.focus();
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