Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
Change one image from html to many different images using javascript

i was able to change img src using javascript, however, I can't figure out how to add multiple images to one function so that when I click on the image it should keep on changing images, it only works with one image please help me

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.1/css/all.min.css">
</head>
<body>
    <h1 id="heading">all abount sports</h1>
    <img id="cool" src="intro-1647872367.jpg"  onclick="changeImage();">
</body>
</html>

<script>
function changeImage() {
  var image = document.getElementById('cool');
  if (image.src.match("beverages-carbonated-drink-cold-drink-1571849")) {
    image.src = "intro-1647872367.jpg";
  } else {
    image.src = "beverages-carbonated-drink-cold-drink-1571849.jpg";


  }
  
  
}

</script>
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda