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

223
Views
Mostrar/ocultar elementos con ajax

Estoy usando AJAX para cargar una lista de capítulos de cómics al hacer clic. Funciona bien. Me gustaría modificar el script para ocultar los capítulos cuando vuelva a hacer clic en el mismo libro. Esperemos que las siguientes imágenes lo aclaren.

Cómo funciona:


Como lo quiero:

El código para cargar los capítulos es el siguiente:

 function aload(element) { var url = element.getAttribute('data-ajax-url'); var xhr = new XMLHttpRequest(); xhr.open("POST", url); xhr.setRequestHeader("X-CSRFToken", csrftoken); xhr.onreadystatechange = function() { if (xhr.readyState === 4){ document.getElementById("chapter-container").innerHTML = this.response; } } xhr.send(); }

Gracias por todas sus sugerencias.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Gracias @Barmar por tus sugerencias, finalmente implementé una solución funcional.

 var previousValue; function compare(element) { var currentValue = element.dataset.bookid; var chapterList = document.getElementById("chapter-container") if (previousValue == currentValue && chapterList.style.display == 'block'){ chapterList.style.display = 'none'; } else{ aload(element); } previousValue = currentValue; }
about 4 years ago · Santiago Gelvez 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!