diff --git a/spec/suites/layer/marker/MarkerSpec.js b/spec/suites/layer/marker/MarkerSpec.js index 9051edc1..63b9e306 100644 --- a/spec/suites/layer/marker/MarkerSpec.js +++ b/spec/suites/layer/marker/MarkerSpec.js @@ -190,6 +190,21 @@ describe("Marker", function () { expect(marker._icon.parentNode).to.be(map._panes.markerPane); expect(marker._shadow.parentNode).to.be(map._panes.shadowPane); }); + + it("sets the alt attribute to an empty string when no alt text is passed", function () { + var marker = L.marker([0, 0], {icon: icon1}); + map.addLayer(marker); + var icon = marker._icon; + expect(icon.hasAttribute('alt')).to.be(true); + expect(icon.alt).to.be(''); + }); + + it("doesn't set the alt attribute for DivIcons", function () { + var marker = L.marker([0, 0], {icon: L.divIcon(), alt: 'test'}); + map.addLayer(marker); + var icon = marker._icon; + expect(icon.hasAttribute('alt')).to.be(false); + }); }); describe("#setLatLng", function () { diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index 15c02301..09c33903 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -203,8 +203,9 @@ export var Marker = Layer.extend({ if (options.title) { icon.title = options.title; } - if (options.alt) { - icon.alt = options.alt; + + if (icon.tagName === 'IMG') { + icon.alt = options.alt || ''; } }