Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
can I make image get focus using className

I want to focus on image link by javascript, the problem is that I don't have direct access to my image.

<li classe="product-1">
  <div classe="shop">
    <a class="img-link" src="xxxxxx">
      <img class="image1">
    </a>
  </div>
</li>

i tried using access to give focus to the image but doesn't work

var imaglink = document.getElementsByClassName("product-1")[0].getElementsByClassName("shop")[0].getElementsByClassName("img-link")[0];
imagelink.focus();

if anyone have any suggestion ho to resolve this probleme i will be thankful

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Possible typo, depending on language I think... I notice in your code you have some lines with classe="..." other times class="..."

with your li element have classe, that might be returning an undefined value, so the rest of your selection isn't going to work.

about 4 years ago · Santiago Trujillo Denunciar

0

const img = document.querySelector("li a > img")
img.focus()

or

const img = document.querySelector(".shop > a img")

or if there multiple images

const img = document.querySelectorAll(".product-1 img")[0]
about 4 years ago · Santiago Trujillo Denunciar

0

You can just combine the selectors together and use querySelector like

document.querySelector(".product-1 .shop .img-link").focus();

document.querySelector(".product-1 .shop .img-link").focus();
a:focus{
  display:inline-block;
  border:20px solid #ccc;
}
<li class="product-1">
  <div class="shop">
    <a href class="img-link">
      <img class="image1" src="https://picsum.photos/200/300">
    </a>
  </div>
</li>

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda