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

178
Vistas
Gallery is not interactive while using JavaScript and Css

I have built a gallery that supposes to change the main picture when other one is chosen from the small menu down below, however, it does not react when i click on other small photos it just stays the same, could anyone please help with it

// image gallery
const changeimage = (src) => {
  document.getElementById("main").src = src
}
.gallery {
  width: 90%;
  margin: 0 auto;
}

.gallery-main {
  width: 45rem;
  height: 30rem;
  margin: 0 auto;
}

.gallery-main img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
}

.gallery-p {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 2rem;
}

.gallery-p img {
  width: 9rem;
  height: 7rem;
  object-fit: cover;
  border-radius: 4px;
  margin: 0.5rem;
  cursor: pointer;
}
<div class="gallery">
  <div class="gallery-main">
    <img src="images/dublin culture1.jpg" alt="" id="main">
  </div>

  <div class="gallery-p">
    <img src="images/dublin culture2.jpg" alt="" onclick="changeimage(this.src)">
    <img src="images/dublin culture3.jpg" alt="" onclick="changeimage(this.src)">
    <img src="images/dublin culture4.jpg" alt="" onclick="changeimage(this.src)">
    <img src="images/dublin people1.jpg" alt="" onclick="changeimage(this.src)">
    <img src="images/dublin people2.jpg" alt="" onclick="changeimage(this.src)">
    <img src="images/dublin people3.jpg" alt="" onclick="changeimage(this.src)">
  </div>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this!

document.getElementById("main").src = "https://i.ibb.co/2kfJ15Z/image-cropped.jpg"

const changeimage = (src) => {
    document.getElementById("main").src = src
}
.gallery {
  width: 90%;
  margin: 0 auto;
}

.gallery-main {
  width: 45rem;
  height: 30rem;
  margin: 0 auto;
}

.gallery-main img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
}

.gallery-p {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 2rem;
}

.gallery-p img {
  width: 9rem;
  height: 7rem;
  object-fit: cover;
  border-radius: 4px;
  margin: 0.5rem;
  cursor: pointer;
}
<div class="gallery">
  <div class="gallery-main">
    <img src="images/dublin culture1.jpg" alt="" id="main">
  </div>

  <div class="gallery-p">
    <img src="https://i.ibb.co/2kfJ15Z/image-cropped.jpg" alt="" onclick="changeimage(this.src)">
    <img src="https://i.ibb.co/0GwkygJ/imagename-2.png" alt="" onclick="changeimage(this.src)">
    <img src="https://i.ibb.co/2kfJ15Z/image-cropped.jpg" alt="" onclick="changeimage(this.src)">
    <img src="https://i.ibb.co/0GwkygJ/imagename-2.png" alt="" onclick="changeimage(this.src)">
    <img src="https://i.ibb.co/2kfJ15Z/image-cropped.jpg" alt="" onclick="changeimage(this.src)">
    <img src="https://i.ibb.co/0GwkygJ/imagename-2.png" alt="" onclick="changeimage(this.src)">
  </div>
</div>

Thanks and best regards!

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