Dantes (обсуждение | вклад) Нет описания правки |
Dantes (обсуждение | вклад) Нет описания правки |
||
| Строка 2: | Строка 2: | ||
var content = element.nextElementSibling; | var content = element.nextElementSibling; | ||
var isExpanded = content.classList.contains('expanded'); | var isExpanded = content.classList.contains('expanded'); | ||
var parentBlock = element.closest('.recipe-block'); | var parentBlock = element.closest('.recipe-block'); | ||
var allSections = parentBlock.querySelectorAll('.section-content'); | var allSections = parentBlock.querySelectorAll('.section-content'); | ||
var allTitles = parentBlock.querySelectorAll('.section-title'); | |||
allSections.forEach(section => section.classList.remove('expanded')); | |||
allTitles.forEach(title => title.classList.remove('expanded')); | |||
if (!isExpanded) { | if (!isExpanded) { | ||
content.classList.add('expanded'); | content.classList.add('expanded'); | ||
element.classList.add('expanded'); | |||
} | } | ||
} | } | ||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function () { | ||
var sections = document.querySelectorAll('.section-content'); | var sections = document.querySelectorAll('.section-content'); | ||
sections.forEach(section => section.style.display = 'none'); | |||
}); | }); | ||
Версия от 02:54, 17 июня 2025
function toggleSection(element) {
var content = element.nextElementSibling;
var isExpanded = content.classList.contains('expanded');
var parentBlock = element.closest('.recipe-block');
var allSections = parentBlock.querySelectorAll('.section-content');
var allTitles = parentBlock.querySelectorAll('.section-title');
allSections.forEach(section => section.classList.remove('expanded'));
allTitles.forEach(title => title.classList.remove('expanded'));
if (!isExpanded) {
content.classList.add('expanded');
element.classList.add('expanded');
}
}
document.addEventListener('DOMContentLoaded', function () {
var sections = document.querySelectorAll('.section-content');
sections.forEach(section => section.style.display = 'none');
});