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

150
Views
Javascript es igual a se resalta en la declaración if

Así que estaba haciendo un carrusel bastante simple en el que cuando un usuario hace clic en un botón, la imagen o el contenido cambia. Conseguí que funcionara a mitad de camino, pero solo soy un problema. En el código, primero verifico si la visualización de la tarjeta 1 está bloqueada y la visualización de la tarjeta 3 es ninguna. Ahí es donde muestra el problema. En la primera parte está bien, pero después de && cuando escribo card3.style = "display:none" resalta los iguales para firmar y no funciona. Intenté cambiar la orientación del código e incluso agregar == pero fue en vano. ¿Puede alguien ayudarme con esto?

Puedes revisar mi código:

 <div class="card1" id="card1"> </div> <div class="card2" id="card2"> </div> <div class="card3" id="card3"> </div> <button onclick="change()">Change</button>
 .card1{ width: 40%; height: 40%; background-color: blue; } .card2{ width: 40%; height: 40%; background-color: red; display: none; } .card3{ display: none; width: 40%; height: 40%; background-color: green; }
 var card1 = document.getElementById("card1") var card2 = document.getElementById("card2") var card3 = document.getElementById("card3") function change(){ if(card1.style = 'display:block;' && card3.style = 'display:none'){ card1.style = 'display:none'; card2.style = 'display:block'; } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Usa == para comparar:

 var card1 = document.getElementById("card1") var card2 = document.getElementById("card2") var card3 = document.getElementById("card3") function change(){ if(card1.style.display == 'block' && card3.style.display == 'none'){ card1.style = 'display:none'; card2.style = 'display:block'; } }
about 4 years ago · Juan Pablo Isaza Report

0

Use el operador == y actualice card1.style a card1.style.display .

 var card1 = document.getElementById("card1"); var card2 = document.getElementById("card2"); var card3 = document.getElementById("card3"); function change() { if (card1.style.display == 'block' && card3.style.display == 'none') { card1.style = 'display:none'; card2.style = 'display:block'; } }
 .card1 { width: 40%; height: 40%; background-color: blue; } .card2 { width: 40%; height: 40%; background-color: red; } .card3 { display: none; width: 40%; height: 40%; background-color: green; }
 <div class="card1" id="card1" style="display: block;"> Card 1 </div> <div class="card2" id="card2" style="display: none;"> Card 2 </div> <div class="card3" id="card3" style="display: none;"> Card 3 </div> <button onclick="change()">Change</button>

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!