Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!