Drupak Drupal Career Development Program
Tabs & Accordions
This video, part of a JavaScript training series, provides a practical tutorial on building two common web UI elements: Tabs and Accordions.
Creating Tabs
- Markup: The presenter structures tabs using a wrapper, buttons with
data-tab-idattributes, and correspondingdivpanels. - Logic: Using JavaScript, the code selects all buttons and panels. It adds a click event listener that captures the
data-tab-id. It then loops through the panels, showing the one that matches the clicked ID while setting thehiddenattribute totruefor others. - Dynamic Handling: The presenter demonstrates how to programmatically hide non-active tabs upon initial page load.
Creating Accordions
- Structure: Each accordion item consists of a header and a body. The headers include a
+sign using CSS::after. - CSS Animation: The bodies are initially hidden with
max-height: 0andoverflow: hidden. Theactiveclass is used to toggle the icon to a-sign. - JavaScript Functionality:
- The code targets
nextElementSibling(the body) and updates itsmax-heightusing thescrollHeightproperty for smooth content display. - Logic improvements: The presenter adds conditional logic to allow clicking an open header to close it, and ensuring that clicking a new header automatically closes any previously opened ones to maintain a clean UI.
- The code targets
Course Content
01
HTML, CSS And Tailwind CSS
02
JavaScript: Basic to Advanced
04
Advanced PHP Development
06
Drupal Development Masterclass
WHY CHOOSE US AS YOUR DRUPAL PARTNER?
We combine strong technical skills, business insight and hands-on Drupal AI experience in every project. With over 100 projects delivered since 2012, an Acquia-certified team and clear, honest communication, we turn complex technology into a real advantage for your business.