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

195
Views
agregue el atributo Alt a todas las imágenes - Vanilla Javascript

¿Cómo podría recorrer todas las imágenes, recuperar el título de la imagen y luego agregarlo al atributo alt?

 function addAltAtrr() { //get the images let grabImage = document.querySelectorAll("img"); //loop through all images for (let i = 0; i < grabImage.length; i++) { grabImage[i].setAttribute("alt", "test"); } } addAltAtrr();

Esto actualmente agrega la cadena "texto" como un atributo alt

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

0

Puede utilizar las propiedades alt y title , que reflejan los atributos de los mismos nombres. Esto supone que por "título" se refiere al atributo de title , que se muestra como una información sobre herramientas al pasar el mouse. Si se refiere al nombre del archivo, podría usar el src del elemento de la imagen, pero probablemente querrá procesarlo, eliminando la extensión del archivo, por ejemplo.

También tenga en cuenta que los lectores de pantalla pueden hablar tanto alt como title , lo que sería redundante si uno se basa en el otro.

 function addAltAttrs() { //get the images let images = document.querySelectorAll("img"); //loop through all images for (let i = 0; i < images.length; i++) { //add alt text if missing (but title is present) if (images[i].title && !images[i].alt) { images[i].alt = images[i].title; } } } addAltAttrs();
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!