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

143
Vistas
if an "url image" is equal to an image got by document.getElementsByTagName("img")?

I am trying to get all images and check if one of these images is equal to an image (specified by me) change it to another image (specified by me). Thanks!

var object = document.getElementsByTagName("img");
//object[0].src is = to "image/image1.png";
if(object[0].src == "image/image1.png")   {
    object[0].src = "image/image2.png"
}   
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use a for loop to check each image:

var images = [...document.getElementsByTagName("img")]

for (const image of images) {
    if (image.src === "image/image1.png") {
        // do something
        image.src = "somethingelse.png"
    }
}

[...] converts the HTMLCollection document.getElementsByTagName returns so you can iterate over it.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I found the solutions by debugging!.

so i was trying to check if an image is equal to an image of the all images i got (specifing one of them for example the first image so object[0]) in var object by document.getElementsByTagName("src)

with this if: if(object[0].src == "image/image1.png) this return always false because object[0].src return file:///C:/Users/Name/Documents/foldername/image/image1.png" so checking if this is equal to "image/image1.png" return always false. and the solution is:

if(object[0].src == file:///C:/Users/Name/Documents/foldername/image/image1.png"){ 
         //do something
    }

to know the complete url: alert(object[0].src);

sorry for my bad English!

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