Open popup programmatically

Open a markers popup from a button.

<!DOCTYPE html>
<meta charset=utf-8 />
<title>Open popup programmatically</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src=''></script>
<link href='' rel='stylesheet' />
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
.ui-control {

<div id='map'></div>
<button id='open-popup' class='ui-control'>open popup</button>

L.mapbox.accessToken = '<your access token here>';
var map ='map', 'mapbox.dc-markers');

// Wait until the markers are loaded, so we know that `map.featureLayer.eachLayer`
// will actually go over each marker.
map.featureLayer.on('ready', function(e) {
    document.getElementById('open-popup').onclick = clickButton;

function clickButton() {
    map.featureLayer.eachLayer(function(marker) {
        // You can replace this test for anything else, to choose the right
        // marker on which to open a popup. by default, popups are exclusive
        // so opening a new one will close all of the others.
        if ( === 'Capital Pride Parade') {
to create your own custom map and use it in this example.
Use this example by copying its source into your own HTML page and replacing the Map ID with one of your own from your projects. Having trouble with JavaScript? Try out Codecademy or contact our support team.
Copy example