I have a pretty simple question, but i'm really stuck on this and can't get it working.
I have an svg that contains a rectangle with an id 'bridge'. I want to get its fill color in console.
I thought "document.getElementById('bridge').style.fill" should work but it just returns an empty string. I tried some other ways but they all didn't work.
Please help me to get rectangle's fill color with plain javascript and explain why style.fill return an empty string.
let bridge=document.getElementById('bridge');
bridge.addEventListener('click', function() { console.log(bridge.style.fill); });
<svg id="game" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 600 300">
<rect id="bridge" x="200" y="100" width="200" height="300" rx="10" fill='#80c41e'/>
</svg>