Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get SVG path d attribute using path id

I have separate json containing SVG path Ids. Is there a way to get SVG path 'd' attribute using path id? Or is there a way to fill SVG path only using path Id?

like image 736
Dis_Pro Avatar asked Jun 29 '26 14:06

Dis_Pro


1 Answers

You can get the path element by calling document.getElementById and from there you can get/set attributes...

var d = document.getElementById("<path id>").getAttribute("d");

document.getElementById("<path id>").setAttribute("fill", "red"); 
like image 147
Robert Longson Avatar answered Jul 01 '26 04:07

Robert Longson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!