使用javascript更改svg内所有元素的填充 [英] Change the fill of all elements inside an svg using javascript
本文介绍了使用javascript更改svg内所有元素的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改SVG内所有元素的填充颜色。元素都是rect和polygon。我没有设置默认颜色。
I would like to change the fill color of all elements inside an SVG. The elements are both type rect and polygon. I have not set a default color.
这是一个示例文件:
http://www.kingoslo.com/instruments/test.svg
我怎样才能最优雅地做到这一点?
How can I do this most elegantly?
推荐答案
如果你有jQuery:
If you have jQuery:
$('svg').children().css('fill', '#ffffff');
编辑:请注意,这假设rects和多边形是svg元素的直接子元素。
Note that this assumes the rects and polygons are the direct children of the svg element.
这篇关于使用javascript更改svg内所有元素的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文