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")
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")
Sahi 有一个get 属性 API和一个圆选择器所以应该可以做一个_getAttribute(_svg_circle($selector), "fill")
这有效 document.getElementsByTagName("circle")[0].getAttribute("fill"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.