document.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. document.querySelectorAll('.accordion-item__trigger').forEach((item) =>
  2. item.addEventListener('click', () => {
  3. const parent = item.parentNode;
  4. const link = parent.querySelector('.link-item');
  5. if (parent.classList.contains('accordion-item--active')) {
  6. parent.classList.remove('accordion-item--active');
  7. } else {
  8. document
  9. .querySelectorAll('.accordion-item')
  10. .forEach((child) => child.classList.remove('accordion-item--active'))
  11. parent.classList.add('accordion-item--active');
  12. }
  13. if (link.classList.contains('link-item--active')) {
  14. link.classList.remove('link-item--active');
  15. } else {
  16. document
  17. .querySelectorAll('.link-item')
  18. .forEach((child) => child.classList.remove('link-item--active'))
  19. link.classList.add('link-item--active');
  20. }
  21. // if (parent.classList.contains('accordion-item--active')) {
  22. // link.style.color = 'gray';
  23. // } else {
  24. // link.style.color = 'blue';
  25. // }
  26. })
  27. )