Search
 
SCRIPT & CODE EXAMPLE
 

HTML

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');
        }
    })
}
Comment

How to create collapsable using pure Javascript

.collapsable-container #expand {
   display:none;
}
.collapsable-container.show #expand {
    display:block;
}
Comment

How to create collapsable using pure Javascript

<div class="collapsable-container">
    <a 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 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>
Comment

PREVIOUS NEXT
Code Example
Html :: db sheets 
Html :: am pm after the time in html 
Html :: laravel route explicit binding 
Html :: equal symbol expected spring form 
Html :: html language 
Html :: html to text 
Html :: cron job visit url each 15 min cpanel 
Html :: cambiar valor de atributo colspan jquery 
Html :: attribut html 
Html :: change api date 
Html :: link href to a class on another page 
Html :: css: how to change SVG color when :hover on Parent element 
Html :: surrealcms content reigons 
Html :: hoe to make a html page attractive 
Html :: tab indent in html 
Html :: como meter imagem html code 
Html :: Reveal css animations 
Html :: bootstrap form navbar for add new row 
Html :: control icon size html 
Html :: disable html line wrapping in vs code 
Html :: how to spread links from not right next to each other html 
Html :: how to convert divs to accordians responsively 
Html :: How to add link on bar for google bar chart 
Html :: 7th science book 
Html :: display pdf in html fastapi 
Html :: loader bootstrap 4 
Html :: add .class to another class html 
Html :: dashboard html arduino 
Html :: typo3 fluid form input text 
Html :: unsplash image for html 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =