Is there a component that functions as a dropdown menu? I've searched online but can't seem to

I have been working on creating a website that allows users to download PDF and MP3 files of sermons. However, I am facing challenges in implementing a dropdown menu for this functionality.

Despite searching resources like Bootstrap and W3schools, I have not been able to find a solution.

<script>

    function myFunction() {
        document.getElementById("myDropdown").classList.toggle("show");
    }

    window.onclick = function(event) {
        if (!event.target.matches('.dropbtn')) {
            var dropdowns = document.getElementsByClassName("dropdown-content");
            var i;
            for (i = 0; i < dropdowns.length; i++) {
                var openDropdown = dropdowns[i];
                if (openDropdown.classList.contains('show')) {
                    openDropdown.classList.remove('show');
                }
            }
        }
    }
</script>


<li>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson </button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson </button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson 3</button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson 4</button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson 5</button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson 6</button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
</li>

This is the current state of my progress, but it does not meet my expectations.

Answer №1

Yes, Bootstrap includes dropdown menus in its components.

You can find more information about Bootstrap dropdowns at this link.

Additionally, W3Schools also has tutorials on dropdown menus (although some may prefer other sources).

You can check out W3Schools' CSS dropdown tutorial at this link.

Answer №2

If you're looking for various parts, Polymer offers a wide selection. For instance:

https://www.webcomponents.org/search/dropdown

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The canvas will not show up, but it will magically appear on its own

Having trouble incorporating this script within a section or any other element? The script works perfectly on its own, but once loaded within a section, it fails to function properly. Below is the script in question; <!-- partial:index.partial.html --& ...

Customize jQuery slideDown animation to have a specific height and handle overflow situations

Below is the HTML snippet I am working with: <div class="text">bla bla bla bla</div> <div class="button">Show</div> Here is the corresponding CSS: .text{ height:100px; overflow:hidden; } Imagine the .text div contain ...

What are effective solutions to reduce the increasing Next.js bundle size caused by dynamic component lookup?

tldr: For more information, please visit the repository. The common.js file includes all dependencies, even though only one is used on the current page. http://localhost:3000/components/ComponentOne http://localhost:3000/components/ComponentTwo Live dem ...

Issue with "Access-Control-Allow-Origin" header missing in express and react application

I've decided to work on a Node/Express project to improve my JavaScript skills, but I'm facing an issue with 'Access-Control-Allow-Origin'. For some reason, I can't do a get request from the front end and despite looking at other p ...

Web page experiencing "increased magnification during loading"

I've been experiencing an issue with my mobile site where the page loads as if it's zoomed in every time. I can easily scale it on a touch phone to make it look right, but I'm looking for ideas on how to prevent this from happening altogethe ...

Adjusting the dimensions of the "overflow avatar" to be consistent with the other avatars displayed in AvatarGroup

When setting the max prop of the AvatarGroup, the additional avatar does not match the height of the other avatars. <AvatarGroup max={3}> <Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" sx={{ width: 24, height: 24 ...

Choose an element from within a variable that holds HTML code

I have a specific div element that I need to select and transfer to a new HTML file in order to convert it into a PDF. The issue I'm facing is related to using AJAX in my code, which includes various tabs as part of a management system. Just to prov ...

Is the value being used as the key for the array of objects?

Here is an array of objects: { 'data': [{ value: 1000, year: 1990 }, { value: 1001, year: 1990 }, { value: 1002, year: 1990 }, ...

After relocating JavaScript code into modules, encountering an error stating 'Cannot read property ClassList of Undefined'

Looking for some guidance in separating my JS code into modules. Everything was working fine when it was all in one file, but after moving it to a module, I'm running into issues. My goal is to make certain elements on my site change visibility based ...

Problem with ng-switch inside ng-repeat

There is a peculiar issue that's been bothering me I have a variety of articles such as news, tweets, and videos in a list. This is how I render them: <div ng-repeat="item in items | orderBy:-timestamp track by item.id" ng-switch="item.type"> ...

Showcase multiple examples of three.js on a single webpage

I need to showcase several 3D objects on my web app within different containers. Currently, I'm creating multiple three.js renderers, each for a separate container. However, I encountered an error message: "WARNING: Too many active WebGL contexts. Old ...

Tips on how to rewind a glTF animation in Three.js if it does not intersect with an object

I have been experimenting with incorporating a gltf model into a three js project and I'm wondering if there's a way to reverse a gltf animation when the mouse moves away from the model. Currently, I've managed to trigger the animation as th ...

Creating a Discord Bot: Building an Embed Table/List with Segmented Sections

Currently in the process of learning Javascript and venturing into discord.js, I'm fully aware that the code I am working with is not up to par and requires some serious refinements. The main objective here is to split up the arguments of a command a ...

What is the best way to create a TypeScript interface or type definition for my constant variable?

I'm facing challenges in defining an interface or type for my dataset, and encountering some errors. Here is the incorrect interfaces and code that I'm using: interface IVehicle { [key: number]: { model: string, year: number }; } interface IV ...

Encountering difficulties in JavaScript while trying to instantiate Vue Router

After following the guide, I reached the point where creating a Vue instance was necessary (which seemed to work). However, it also required providing a Vue Router instance into the Vue constructor, as shown below. const router = new VueRouter({ routes }) ...

Splitting the screen into four sections using Bootstrap 4 Flexbox

Is there a way to split my screen into four sections with equal width and height using bootstrap 4 and flexbox? Each section should occupy 50% of the screen's width and height. Additionally, I need these sections to be responsive in terms of their c ...

How to retrieve the changing input value in ReactJS using Jquery/JS

I have a form in WordPress with two input range sliders. The form calculates the values of these sliders and displays the result as shown below: <input data-fraction-min="0" data-fraction="2" type="hidden" data-comma=" ...

Event handler or callback function in Socialite.js

Exploring the capabilities of Socialite.js for the first time has been quite intriguing. This JavaScript plugin allows loading social media plugins after page load, adding an interesting dynamic to website interactivity. However, I am faced with the challe ...

Only the main page is accessible quickly through Express

Currently, I am delving into learning Express and leveraging FS to load my HTML Page. My research on this topic only led me to references of using ASP.NET instead of Express. Here is a snippet from my Server.js file: var express = require('express&a ...

Tips for preventing automatic zoom on mobile devices

Check out this link for the test: The current layout of the site is exactly how I want it to be presented. However, I am facing an issue where if I set the viewport meta tag to <meta name="viewport" content="width=device-width, initial-scale=1"> i ...