Kevin Waterson
Kevin Waterson

Reputation: 837

How to add CSS class to Leaflet Control

I wish to assign CSS classes to a leaflet control. The control works fine, but I wish to style it.

var search = L.Control.geocoder({
    collapsed:false, placeholder:"Search Criteria", position:'topright'
});
search.setStyle({className: 'form-control'});
search.addTo(map);

The error from this is Uncaught (in promise) TypeError: search.setStyle is not a function

Obviously, setStyle is not a function of the search object. How do I set a custom style for this element?

Upvotes: 0

Views: 1723

Answers (1)

Falke Design
Falke Design

Reputation: 11338

You have to get the html/DOM container of the control with search.getContainer() and then you can add a css class.

L.DomUtil.addClass(search.getContainer(),'form-control')

Upvotes: 4

Related Questions