Jquery Accordion Expand All Collapse All
Tag : jquery , By : Kilimanjaro
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I would add a class or ID to the expand and collapse links then something like this will work $(document).ready(function() {
$("#expand").click(function(){
('.answer').slideDown('normal');
});
$("#collapse").click(function(){
('.answer').slideUp('normal');
});
}
|
jQuery UI Accordion Expand/Collapse All
Date : March 29 2020, 07:55 AM
I wish this help you In the end I found this to be the best solution considering the requirements: // Expand/Collapse all
$('.accordion-expand-collapse a').click(function() {
$('.accordion .ui-accordion-header:not(.ui-state-active)').next().slideToggle();
$(this).text($(this).text() == 'Expand all' ? 'Collapse all' : 'Expand all');
$(this).toggleClass('collapse');
return false;
});
|
Expand/Collapse jQuery Accordion at runtime
Date : March 29 2020, 07:55 AM
I hope this helps . Here is the API documentation. Basically you change the active option: var index = 1; // Opens the second panel
// If collapsible is true collapses all the rest
$('#accordian').accordion('option', 'active', index);
|
Jquery UI Accordion expand/collapse
Date : November 16 2020, 06:27 AM
this will help If you just want your links to show and hide then refer to Fiddle demoYou just have to register the click events on your classes and then show and hide according to where click happens.
|
Accordion Expand/Collapse All Without jQuery
Date : March 29 2020, 07:55 AM
To fix this issue I believe this is what you want, basically I added two buttons and attached click event listener on click event and based on the button clicked we have to hardcode the hight of the accordion content. var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
document.getElementById('collapse-all').addEventListener('click', function(e) {
for (i = 0; i < acc.length; i++) {
acc[i].classList.add('active');
var panel = acc[i].nextElementSibling;
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
document.getElementById('close-all').addEventListener('click', function(e) {
for (i = 0; i < acc.length; i++) {
acc[i].classList.remove('active');
var panel = acc[i].nextElementSibling;
panel.style.maxHeight = null;
}
});
.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
}
.active, .accordion:hover {
background-color: #ccc;
}
.accordion:after {
content: '\002B';
color: #777;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2212";
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<button id="collapse-all">Collapse all</button>
<button id="close-all">Close all</button>
<h2>Accordion with symbols</h2>
<p>In this example we have added a "plus" sign to each button. When the user clicks on the button, the "plus" sign is replaced with a "minus" sign.</p>
<button class="accordion">Section 1</button>
<div class="panel">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<button class="accordion">Section 2</button>
<div class="panel">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<button class="accordion">Section 3</button>
<div class="panel">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
|