Toggle in Vanilla JavaScript | Pure JavaScript Tutorial

Publicado em: 06 Junho 2021
no canal de: WebStylePress
1,475
8

Create toggle function for multiple cards by using vanilla JavaScript. Toggle class by using vanilla JavaScript. We have two cards containing title and details area. Clicking at card title will toggle its details area.

At click of card title we will toggle details area. We will use vanilla JavaScript to create toggle function. First of all we will add an event listener at document that will listen to DOM being loaded, when DOM will be ready, it will fire toggle function.

We will select all elements with a perticular class and for each title we will add click event listener. We will use preventDefault for title so that in case title is an anchor, it may not reload page.

We will declare a variable and from title that was clicked, we will find its outer closest element and find toggle able area inside it. Then we will toggle it and if the area is being opened or ON, we will also apply a class at the wrapper. If area is closed, our function will open it, or in other case area will be closed.

This is basically like jQuery hide and show methods but without jQuery. And this is how you can create toggle functionality in pure vanilla JavaScript without jQuery.

✅ How To Hide / Protect JavaScript Code - Techniques and Tools
   • How To Hide / Protect JavaScript Code | Ja...  
✅ React JS UNDEFINED Solution | Reactjs Learning | Learn ReactJS & JavaScript Debugging Fast
   • How to Prevent TypeError Cannot Read Prope...  
✅ Calculate Sum or Total from Values in Array & Array Object | Learn JavaScript | Reduce Method
   • How to Find Sum of An Array of Numbers in ...  
✅ Get URL Parameters in JavaScript | URLSearchParams
   • Get URL Parameters in JavaScript | URLSear...  
✅ DIV to PDF, Iframe to PDF using JavaScript Only (with CSS & Images Support)
   • DIV to PDF, Iframe to PDF using JavaScript...  
✅ How To UnMinify JavaScript Minified Files Easily | Decrypt Complex JavaScript Code
   • How To UnMinify JavaScript Minified Files ...  
✅ Toggle Class in Vanilla JavaScript | Learn JavaScript
   • Toggle Class in Vanilla JavaScript  
✅ How to Execute a JavaScript File by using NPM
   • How to Run a JavaScript File using NPM  
✅ Get User's Location (Country, State, City) with Free Unlimited API Access | PHP & JavaScript
   • Get User Location (Country, State, City) w...  
✅ Replace jQuery with Vanilla JavaScript Code Easily | jQuery vs JavaScript
   • Replace jQuery with Vanilla JavaScript Cod...  
✅ Toggle in Vanilla JavaScript
   • Toggle in Vanilla JavaScript | Pure JavaSc...  
✅ MINIFY JAVASCRIPT FILES & FOLDERS in Multiple Ways (Command Line & Code Editor)
   • MINIFY JAVASCRIPT FILES & FOLDERS in Multi...  
✅ JavaScript vs jQuery | Difference between JavaScript and jQuery
   • JavaScript vs jQuery | Difference between ...  
✅ JavaScript Variable Redeclare & Reassign | VAR vs LET vs CONST | Practical Examples
   • VAR vs LET vs CONST | JavaScript Variable ...  

Thank You!
👍 LIKE VIDEO
👊 SUBSCRIBE
🔔 PRESS BELL ICON
✍️ COMMENT

Channel:    / webstylepress  
Website: https://www.webstylepress.com
FaceBook:   / webstylepress  
Twitter:   / webstylepress  
Instagram:   / webstylepress  
LinkedIn:   / webstylepress  
GitHub: https://github.com/webstylepress
#js #javascript #toggle #vanillajs #webstylepress #tutorials #webdevelopment


Nesta página do site você pode assistir ao vídeo on-line Toggle in Vanilla JavaScript | Pure JavaScript Tutorial duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário WebStylePress 06 Junho 2021, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,475 vezes e gostou 8 espectadores. Boa visualização!