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

64
Views
cómo mostrar la imagen al hacer clic y ocultarla nuevamente al hacer clic nuevamente

Quiero cuando hago clic en una frase o en un botón aparece una imagen y cuando hago clic de nuevo desaparece. pero mi código no parece funcionar usando JS y HTML.

 let pic = document.getElementById("hiddenclickimg"); let word = document.getElementById("hiddenclick"); function showPic(){ pic.hidden = 'false' ; word.style.color = 'red'; word.style.backgroundColor = 'blue'; } word.onclick = showPic;
 <h3 id="Work">Work Experience</h3> <div class="work"> <ul> <li> <img src="./Images/Alex Sydney.jpg" alt="alex sydney" id="hiddenclickimg" hidden="true" /> <button id="hiddenclick">Alex Sydney Hospital</button> </li> </ul> </div> <script src="./main.js"></script>

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

0

Puede usar el clic de un botón y alternar una clase que oculta la imagen cuando tiene esa clase.

HTML:

 <button onclick="imageClick()">Toggle Image</button>

CSS:

 .hidden { opacity: 0; }

JavaScript:

 const image = document.getElementById('hiddenclickimg'); const imageClick = () => { image.classList.toggle('hidden'); }

Hay diferentes propiedades de CSS que podría usar para ocultar la imagen, pero la opacidad es una buena básica.

about 4 years ago · Juan Pablo Isaza Report

0

No necesita configurar 2 ID para hacer el truco usando la propiedad css display none .

Por ejemplo, desea ocultar esa imagen:

 <img id="dog_image" src="dog.png" alt="Rex the Labradoodle" > function hideDog() { const dog = document.getElementById("dog_image"); if (dog.style.display === "none") { dog.style.display = "block"; } else { dog.style.display = "none"; } }

Y luego simplemente configure el botón:

 <button onclick="hideDog()">Hide/Show my dog</button>
about 4 years ago · Juan Pablo Isaza Report

0

puede usar la bandera para cambiar el estado de la imagen como sigue

 let imagehidden =false let pic = document.getElementById('hiddenclickimg'); let word = document.getElementById('hiddenclick'); function showPic(){ if(imagehidden){ pic.hidden = false ; word.style.color = 'red'; word.style.backgroundColor = 'blue'; imagehidden=false } else{ pic.hidden =true; imagehidden=true } }
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!