Horje
How to create collapsable using pure Javascript Code Example
How to create collapsable using pure Javascript
.collapsable-container #expand {
   display:none;
}
.collapsable-container.show #expand {
    display:block;
}
How to create collapsable using pure Javascript
<div class="collapsable-container">
    <a rel="nofollow" href="javascript:void(0);" class="collapsable-toggle" data-onOpenText="Hide First Content" data-onCloseText="Show First Content">Show First Content</a>
    <div id="expand">
        This is some Content
    </div>
 </div>
 
 
 <div class="collapsable-container">
    <a rel="nofollow" href="javascript:void(0);" class="collapsable-toggle" data-onOpenText="Hide Second Content" data-onCloseText="Show Second Content">Show Second Content</a>
    <div id="expand">
        This is some Content
    </div>
 </div>
How to create collapsable using pure Javascript
const collapsableBtn = document.querySelectorAll('.collapsable-toggle');

for (let index = 0; index < collapsableBtn.length; index++) {
    collapsableBtn[index].addEventListener('click', function(e) {
        // e.preventDefault();
        e.stopImmediatePropagation();

        iterateElement = this;

        getCollapsableParent = iterateElement.parentElement;

        if(getCollapsableParent.classList.contains('show')) {
            getCollapsableParent.classList.remove('show')
            iterateElement.innerText = iterateElement.getAttribute('data-onCloseText');

        } else {
            getCollapsableParent.classList.add('show');
            iterateElement.innerText = iterateElement.getAttribute('data-onOpenText');
        }
    })
}




Css

Related
wordpress page css not working Code Example wordpress page css not working Code Example
background shorthand Code Example background shorthand Code Example
images end then start text in css Code Example images end then start text in css Code Example
/* */ Code Example /* */ Code Example
width fit content Code Example width fit content Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11