Arpico ICT
Arpico ICT

Reputation: 131

How to get SVG map province, district, title attributes Using javascript

How to get the attributes values from SVG Map path. I used javascript

    
    <object data="https://svgur.com/i/QXQ.svg" type="image/svg+xml" id="map"></object>
        <script>
            var a = document.getElementById("map");
            a.addEventListener("load",function(){
                var svgDoc = a.contentDocument;
                var delta = svgDoc.getElementById("provinceMap");

                delta.addEventListener("mousedown",function(e){
                    console.log(e["path"]);
                }, false);
            }, false);
        </script>
   

Upvotes: 1

Views: 201

Answers (1)

Kanishka
Kanishka

Reputation: 115

This way you can

console.log(e['path'][0].getAttribute("province"));
console.log(e['path'][0].getAttribute("district"));
console.log(e['path'][0].getAttribute("title"));

Upvotes: 1

Related Questions