+ 2
Can I manually code the accordion without downloading and including jQuery files ?
3 Respostas
+ 4
You can manually code anything which is in any framework/library, as they just provide you ready to use codes, but someone write it manually ;)
@James link provide solution for do it without "JQueryUI" ( an extention to JQuery ), but can be easily translate to vanilla ( pure -- without libraries ) JS ( without animation effects: require some more adaptations ^^ ):
window.onload = function() {
var accordions = document.querySelectorAll('#accordion .accordion-toggle');
for (var i=0; i<accordions.length; i++) {
accordions[i].onclick = function(){
// Hide the other panels
// ( at first: avoid testing wich is not to hide :P )
var contents = this.parentElement.getElementsByClassName('accordion-content');
for (var i=0; i<contents.length; i++) {
contents[i].className = 'accordion-content';
}
// Expand or collapse this panel
this.nextElementSibling.className = 'accordion-content default';
};
}
};
Complete code here ( but css and html unchanged ^^ ):
https://code.sololearn.com/W86rM5c1y6uJ/#js
+ 1
I made an accordion with pure CSS and HTML
https://code.sololearn.com/WvHqvisioSJU/#html
0
Thanks😀