How to apply javascript

Asked

Viewed 60 times

-4

I want when the person clicks on option one and then clicks on two, 1 is unchecked.

<script>

        function mudaImagem (foto){
            document.getElementById("vamo") .src =foto;
        }
        function selecionaPequeno(){
            document.getElementById("bora") .src = "imagens/P1.gif";
        }
        function voltaPequeno(){
            document.getElementById("bora") .src = "imagens/P1.png";
        }
        function selecionaMedio(){
            document.getElementById("corre") .src = "imagens/P1.gif";
        }
        function selecionaGrande(){
            document.getElementById("neh") .src = "imagens/G3.png";
        }
        function selecionaGigantesco(){
            document.getElementById("jeh") .src = "imagens/GG3.png";
        }


</script>

HTML

<img src="imagens/P1.png" id="bora" name="opa" onclick="selecionaPequeno()" width="56" height="35" />
<img src="imagens/P1.png" id="corre" name="opa" onclick="selecionaMedio()" width="56" height="35" />
  • Missing details on your question, unchecked what? Put the full code or a good part to understand what you need.

  • You can join the HTML of these options?

1 answer

0

The explanation was not clear but I believe the idea is this:

HTML

<img id="bora" name="opa" src="https://icon-icons.com/icons2/577/PNG/256/ExecutiveCar_Black_icon-icons.com_54904.png"/>
<img id="corre" name="opa"src="https://images.vexels.com/media/users/3/127817/isolated/lists/4fd0c9dcae60a9a63579b9b6853eeb09-carro-de-besouro-retro-brilhante.png" />

JAVASCRIPT

$(document).ready(function(){
  $("#bora").click(function(){
      $(this).addClass("selected");
      $("#corre").removeClass("selected");
  });
  $("#corre").click(function(){
      $(this).addClass("selected");
      $("#bora").removeClass("selected");
  });
});

CSS

.selected { border: 2px dashed red; }

RESULT

inserir a descrição da imagem aqui

See working here: https://jsfiddle.net/rodrigorf/3mqp75oa/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.