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

185
Views
cómo obtener un elemento secundario usando javascript en línea en htmltag

Aquí está el código

 <a href="http://example.com/example-2pp.html" onmouseover="alert(this.children[1].src)"> <span class="product-image-container product-image-container-1198" style="width: 388px;"> <span class="product-image-wrapper" style="padding-bottom: 125%;"> <img class="product-image-photo" src="http://example.com/media/catalog/product/l/i/example_d17163a-a00_t-shirt_bra_white-min.jpg?width=388&amp;height=485&amp;store=example_en&amp;image-type=small_image"> </span> </span> </a>

Quiero obtener el img src usando esta línea de script

 onmouseover="alert(this.children[1].src)">

¿Es posible hacer eso?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • Usar Element.querySelector
  • Use el nombre del evento "mouseenter"
  • PD: Evite el uso de atributos de style o on* línea. ¡JS y CSS deben estar en sus respectivas etiquetas o archivos!

 <a href="http://example.com/example-2pp.html" onmouseenter="alert(this.querySelector('img')?.src)"> <span class="product-image-container product-image-container-1198" style="width: 388px;"> <span class="product-image-wrapper" style="padding-bottom: 125%;"> <img class="product-image-photo" src="http://example.com/media/catalog/product/l/i/example_d17163a-a00_t-shirt_bra_white-min.jpg?width=388&amp;height=485&amp;store=example_en&amp;image-type=small_image"> </span> </span> </a>

No utilice los atributos inline on* y style . Bastante:

 const ELS_prodLink = document.querySelectorAll(".product-link"); ELS_prodLink.forEach((EL_pr) => { EL_pr.addEventListener("mouseenter", () => { const EL_img = EL_pr.querySelector(".product-image-photo"); console.log(EL_img.src); }); });
 .product-image-container { width: 388px; } .product-image-wrapper { padding-bottom: 125% }
 <a class="product-link" href="http://example.com/example-2pp.html"> <span class="product-image-container product-image-container-1198"> <span class="product-image-wrapper" > <img class="product-image-photo" src="http://example.com/media/catalog/product/l/i/example_d17163a-a00_t-shirt_bra_white-min.jpg?width=388&amp;height=485&amp;store=example_en&amp;image-type=small_image"> </span> </span> </a>

about 4 years ago · Juan Pablo Isaza 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!