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

323
Vistas
Accordion does not change the status of the icon

Hi guys I have this script to make an accordion. I am at the first experiences of js, so I ask for help here. What I can't understand is why when I click on the same "Title" label the icon - doesn't change to the + position. I guess the js is missing a function of itself. Thanks everyone for any help.

var acc = document.getElementsByClassName("accordion-mio");
var i;

for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {

var pannello = this.nextElementSibling;
if (pannello.style.maxHeight){
  pannello.style.maxHeight = null;
} else {
  let attivo = document.querySelectorAll(".accordion-mio.attivo");
  for(let j = 0; j < attivo.length; j++){
    attivo[j].classList.remove("attivo");
    attivo[j].nextElementSibling.style.maxHeight = null;
  }
  this.classList.toggle("attivo");
 pannello.style.maxHeight = pannello.scrollHeight + "px";
}
});
}
/* Style the buttons that are used to open and close the accordion panel */
.accordion-mio {
  background-color: #F2F2F2;
  color: #444;
  cursor: pointer;
  padding: 18px;
  width: 100%;
  text-align: left;
  border: none;
  outline: none;
  transition: 0.4s;
  border-bottom:1px #ABABAB solid;
  
}
.attivo, .accordion-mio:hover {
  
  background-color: #ccc;
}

.accordion-mio:after {
  content: '\02795'; /* Unicode character for "plus" sign (+) */
  font-size: 13px;
 color: #444;
  float: right;
  margin-left: 5px;
}

.attivo:after {
  content: '\2796'; /* Unicode character for "minus" sign (-) */
  color: #fff;
}

/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */

/* Style the accordion panel. Note: hidden by default */
.pannello {
  padding: 0 18px;
  background-color: #fff;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;

}


.elenco {margin-top:20px;}
<div class="accordion-mio">Titolo</div>
<div class="pannello"><div class="elenco">testo testo testo</div></div>
<div class="accordion-mio">Titolo</div>
<div class="pannello"><div class="elenco">testo testo testo</div></div>

about 4 years ago · Juan Pablo Isaza
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