Get leaflet marker from a layer

Viewed 2093

I'm new to leaflet and am trying to implement a set of markers with different CSS-styles.

So, I am aware that after adding a marker to a map I can access different CSS-attributes by calling getElement() on my marker for example:

    marker.addTo(map);
    marker.getElement().style.borderColor = '#000';

This works just fine, but when adding a marker to a layer, this can no longer be used since a TypeError occurs (getElement() is undefined). Here is the example code where the error occurs:

    myLayer.addLayer(marker);
    marker.getElement().style.borderColor = '#000';

Am I overlooking a simpler way to set CSS-Attributes for markers and divicons that are added to layers or is there a similar way to access layer-added markers and divicons in JavaScript?

2 Answers
Related