``Why isn't the Bootstrap dropdown menu button displaying properly on a Leaflet map?

I am currently in the process of developing a LeafletJS Map integrated with Bootstrap buttons. I have successfully configured the map to be fullscreen and positioned the buttons on top of it. Below is the code snippet that I utilized for this setup:

<!DOCTYPE html>
<html>
<head>

    <title>Map</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="static/bootstrap/js/bootstrap.min.js"></script>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="shortcut icon" type="image/x-icon" href="static/favicon.ico" />

    <link rel="stylesheet" href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93fff6f2f5fff6e7d3a2bda0bda7">[email protected]</a>/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
    <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3dfd6d2d5dfd6c7f3829d809d87">[email protected]</a>/dist/leaflet.js" integrity="sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==" crossorigin=""></script>
    <link rel="stylesheet" media="screen" href ="static/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="static/bootstrap/css/bootstrap-theme.min.css">

    <style>
        body {
            padding: 0;
            margin: 0;
        }
        html, body, #map {
            height: 100%;
            width: 100%;
        }

        #back_button {
          position: absolute;
          top: 20px;
          left: 20px;
          padding: 10px;
          z-index: 1001;
        }

        #drop_button {
          position: absolute;
          top: 80px;
          left: 20px;
          padding: 10px;
          z-index: 1001;
        }
    </style>


</head>
<body>
    <div id='map'>
    </div>

    <form  action="/" method="post" role="form">
        <button type="submit" class="btn btn-default" id="back_button"><- Back</button>
    </form>

    <div class="dropdown">
      <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" id="drop_button">Dropdown Example
      <span class="caret"></span></button>
      <ul class="dropdown-menu">
        <li><a href="#">HTML</a></li>
        <li><a href="#">CSS</a></li>
        <li><a href="#">JavaScript</a></li>
      </ul>
    </div>
<script>
    var map = L.map('map', {zoomControl:false}).setView([47.57768554635565,-122.16660887002944], 13);

    var coordinate = {{list_latlong | tojson | safe}};
    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(map);
    var logoIcon = L.icon({
        iconUrl: './static/picture.png',
        iconSize:     [22, 22], // size of the icon
        iconAnchor:   [11, 22], // point of the icon which will correspond to marker's location
    });

    var i;
    for (i = 0; i < coordinate.length; i++) {
        var point = coordinate[i]
        var text = "";
        text = "<dl><dt>Number: " + point[2] + "</dt>"
        + "<dt>" + point[5] + "</dt>"
        + "<dt>" + point[6] + ", " + point[7] + ", " + point[8] + "</dt>"
        +"</dl>"
        L.marker([point[3],point[4]], {icon: logoIcon}).bindPopup(text).addTo(map);
    }


</script>
</body>
</html>

Upon executing the above code snippet, only the "Back" button is displayed while the dropdown button does not appear. Removing the following lines from the code:

<link rel="stylesheet" media="screen" href ="static/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="static/bootstrap/css/bootstrap-theme.min.css">

Results in the appearance of both the dropdown button and back button, however, the elements within the dropdown menu fail to display.

Answer №1

I have corrected the issue for you, for multiple reasons. First, the bootstrap link was incorrect. Second, you applied incorrect styles to the wrong ID #dropdown button, causing it to be displayed in the footer where it is not visible. Below is the updated code with corrections made to various file paths and URLs, along with updating the style from #dropdown to the parent div .dropdown.

<!DOCTYPE html>
<html>
<head>

    <title>Map</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" type="image/x-icon" href="static/favicon.ico" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80ece5e1e6ece5f4c0b1aeb3aeb4">[email protected]</a>/dist/leaflet.css"/>

    <style>
        body {
            padding: 0;
            margin: 0;
        }
        html, body, #map {
            height: 100%;
            width: 100%;
        }

        #back_button {
          position: absolute;
          top: 20px;
          left: 20px;
          padding: 10px;
          z-index: 1001;
        }
        .dropdown {
          position: absolute;
          top: 80px;
          left: 20px;
          z-index: 1001;
        }
    </style>
</head>
<body>
    <div id='map'>
    </div>

    <form  action="/" method="post" role="form">
        <button type="submit" class="btn btn-default" id="back_button"><- Back</button>
    </form>
    <div class="dropdown">
      <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" id="drop_button">Dropdown Example
      <span class="caret"></span></button>
      <ul class="dropdown-menu">
        <li><a href="#">HTML</a></li>
        <li><a href="#">CSS</a></li>
        <li><a href="#">JavaScript</a></li>
      </ul>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="38545d595e545d4c7809160b160c">[email protected]</a>/dist/leaflet.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script>
    var map = L.map('map', {zoomControl:false}).setView([47.57768554635565,-122.16660887002944], 13);

    var coordinate = {{list_latlong | tojson | safe}};
    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(map);
    var logoIcon = L.icon({
        iconUrl: './static/picture.png',
        iconSize:     [22, 22],
        iconAnchor:   [11, 22],
    });

    var i;
    for (i = 0; i < coordinate.length; i++) {
        var point = coordinate[i]
        var text = "";
        text = "<dl><dt>Number: " + point[2] + "</dt>"
        + "<dt>" + point[5] + "</dt>"
        + "<dt>" + point[6] + ", " + point[7] + ", " + point[8] + "</dt>"
        +"</dl>"
        L.marker([point[3],point[4]], {icon: logoIcon}).bindPopup(text).addTo(map);
    }


</script>
</body>
</html>

Answer №2

<script src="static/bootstrap/js/bootstrap.min.js"></script>

This particular script is crucial for enabling the functionality of menus and other visually appealing features that rely on JavaScript. However, for it to properly function, it requires a Document Object Model (DOM) to operate within. Currently, the script is executing at the very beginning directly after jQuery, without any DOM elements available (specifically, the menu components have not yet been processed). To resolve this issue, consider moving this script placement just before you conclude your </body> tag. By doing so, it should facilitate the proper functioning of the menu elements.

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

Leveraging an external script for enhanced functionality in React/Meteor application

I'm currently facing a challenge incorporating an external script into my React component within Meteor. I've experimented with directly placing the script tag in my component as follows: TheLounge = React.createClass({ render() { return ( ...

Set up authentication within a separate AngularJS module

I am struggling with how to develop a standalone login page for the BlurAdmin template found on GitHub. The main structure of the template is based on index.html, which includes header, footer, sidebar, and loads pages as templates using ui-view. However, ...

Is it possible for individuals on the local network to view the webpage?

Recently, I developed a login page in HTML that prompts users for their username and password. The information is then sent to ABC.php, and upon successful authentication, they are redirected to another website. To make this work, I set up a xampp server. ...

Identifying a flaw in an HTML5 video

I am attempting to identify when an error occurs while playing an HTML5 video. Specifically, I am encountering a situation where I am trying to play an HLS video on a MAC (where "canPlayType" is at least "maybe"), but the video will not play for unknown r ...

Using only HTML, I have created a collapsible accordion in Angular without the need for JS code. However, when I click the button, nothing happens. Can you help me resolve

I am attempting to add an Accordion button to my website using the HTML code provided below. I am currently incorporating this in a very basic manner, without any utilization of javascript code, within this example of accordion snippet. When the button i ...

Determine the quantity of classes based on the part name

I have the code snippet provided below: <ul id="towns"> <li class="clearfix odd 516_499_132_0_0 town132">...</li> </ul> I am looking to extract the specific class "town132" as a parameter, but the number - such as 132 in this ...

Safari experiences occasional failures with pre-signed post uploads to S3 when using multipart/form-data for file uploads

Lately, I've encountered issues with pre-signed post uploads to S3 that seem to be unique to Mobile Safari browsers. Interestingly, the error has also shown up occasionally on Desktop Safari. Whenever this error occurs, it triggers a response from S3 ...

Creating a Controlled accordion in Material-UI that mimics the functionality of a Basic accordion

I'm a Junior developer seeking assistance with my first question on this platform. Currently, I am working with a Controlled accordion in React and need the icon to change dynamically while staying open even after expanding another panel. The logic ...

The cursor remains positioned below the video within the designated div

I'm currently facing an issue in a project where the cursor div I created stays underneath the video element. No matter what I do, I can't seem to bring it to the front. Even setting a z-index on the video tag hasn't helped. Can someone plea ...

The function in PHP does not arbitrarily return a boolean value

After creating a template file for WordPress, I encountered an issue with a function that I wrote. Despite ensuring that the two variables are different (as I confirmed by printing them), the function consistently returns true. Even after testing and attem ...

When a user connects to Node.js using sockets, the previous messages are loaded. However, a bug causes the messages to be loaded to all chat users, instead of just the

New to node.js, I am currently creating a chat application with two main files: server.js (server side) and script.js (client side). In the server.js file: socket.on('previousMessages', function (data){ db.query("SELECT * FROM messages", f ...

How can I improve the smoothness of my CSS transition when resizing background images?

I'm currently working on creating an intro movie for a game and I thought it would be interesting to use CSS animations. However, I've noticed that some parts of the animation appear bumpy and inconsistent. It seems that depending on the transiti ...

After every refresh, Next.js dynamically applies unique and quirky styles to Bootstrap components

Let's address the issue at hand: Upon opening the page or performing a hard refresh, all components load correctly except for certain buttons and form controls from Bootstrap 4. This leads to an unconventional styled form and icons. I have opted to ...

When attempting to run Protractor, an error occurs indicating that the module '../built/cli.js' cannot be located

Due to an issue present in Protractor 3.3.0 with getMultiCapabilities, we had to install the latest version directly from GitHub where a fix has been implemented (refer to the fix scheduled for Protractor 3.4). To include this fix, we updated our package. ...

Ways to modify the values of a Bootstrap Dropdown using a unique identifier

Here is an example of a typical Bootstrap Dropdown: <div class="btn-group"> <button type="button" class="btn btn-lg btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Default option<span class ...

Is it possible to modify the :hover effects of a material-ui outlined select component?

I am currently developing a react application using Material UI. My goal is to change the color of a selector to white when hovering over it. However, I have encountered difficulties in applying the style as intended. Even when directly adding classes, the ...

Conceal the inactive cursor on a webpage in Google Chrome

Imagine a unique HTML5 video player with a control bar that automatically hides when idle in fullscreen mode. But what if you also want the cursor to disappear? You might try adding .cursor = 'none' to the body's style, but be warned - Chrom ...

Automatically simulate the pressing of the enter key in a text field upon page load using Javascript

I am looking to simulate the pressing of the enter key in a text field when a page is loaded. Essentially, I want the text field to automatically trigger the enter key press event as if it had been pressed on the keyboard by the user. Below is an example o ...

Styling markdown text causes the text to vanish and it is impossible to include a background color

I'm facing a puzzling React markdown problem. Within this snippet: <ReactMarkdown className={styles.reactMarkDown} escapeHtml={false} components={renderers} > {content} </ReactMarkdown> I am attempting to apply a backgr ...

NextJS is throwing an error stating that the element type is invalid. It was expecting either a string for built-in components or a class/function for composite components, but instead received an object

I encountered the following issue: Error - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but received an object. Here's the code from my \components\LayoutWrapper.js: i ...