0

I have too many lines on my leaflet layer control, such that it spills beyond the page. How can I do the below using javascript?

.leaflet-control-layers {
  overflow: auto;
}

What I've tried

  1. This answer

    var controls = L.control.layers(null,overlayMaps,{collapsed: false});  
    controls.addTo(map);  
    controls.style.overflow="auto";
    

    I got that the controls didn't have a style attribute

  2. The second answer to the same question

    document.getElementById("leaflet-control-layers").style.overflow="auto";
    

    Nothing happens

  3. Not sure where I got this, but I guess jQuery wasn't being used in my map

    $(".leaflet-control-layers").style.overflow="auto";
    

    Since this printed ReferenceError: $ is not defined to the console.

  4. From the accepted answer to Modify CSS classes using Javascript

        var layercontrols = document.querySelectorAll('.leaflet-control-layers');
        for(var i=0; i<layercontrols.length; i++){
            layercontrols[i].style.overflow="auto";
        }
    

    (nothing happens)

1 Answer 1

0

If you're just looking to set the div's overflow to auto I don't see why you can't do it in CSS. However I think the reason .style.overflow didn't work is because you did document.getElementById() when 'leaflet-control-layers' is the class not the ID.

Sign up to request clarification or add additional context in comments.

2 Comments

If I get the CSS source from a CDN, is it possible to edit it?
I'm not sure what you mean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.