How to access 'fill' element of circle tag in sahi code

129 Views Asked by At

I want to access the fill element of circle tag in <svg> tag and assign the value to a variable.

fill value is #08C65B.

I tried with the below line but unable to get it:

document.getElementsByTagName("svg")[0].document.getElementsByTagName("circle")[0].getAttribute("fill")

var y = document.getElementsByTagName("svg"[0].document.getElementsByTagName("circle")[0].getAttribute("fill")

enter image description here

3

There are 3 best solutions below

0
JBOSSUSER On BEST ANSWER

This works document.getElementsByTagName("circle")[0].getAttribute("fill"));

0
sourav satyam On
let querySelector = document.getElementsByTagName("svg")[0]
let circleSelector = querySelector.getElementsByTagName("circle")[0]
let filledAttribute = circleSelector.getAttribute("fill")

or

Instead of using

document.getElementsByTagName("svg")[0].document.getElementsByTagName("circle")[0].getAttribute("fill")

Use

document.getElementsByTagName("svg")[0].getElementsByTagName("circle")[0].getAttribute("fill")

2
globalworming On

Sahi has a get attribute API and a circle selector So it should be possible to do a _getAttribute(_svg_circle($selector), "fill")