I have a svg script with a few rects:
<g class="1">
<rect x="80.181" y="156.8" width="64.394" height="54.973"/>
</g>
<g class="2">
<rect x="147.067" y="156.8" width="23.89" height="54.973"/>
</g>
<g class="1">
<rect x="173.45" y="156.8" width="22.433" height="54.973"/>
</g>
<g class="3">
<rect x="198.375" y="156.8" width="39.668" height="54.973"/>
</g>
(...)
And I want to create a function that defines the fill of all rects inside class, for example, 1. Something like:
function FillRect() {
var rect = document.getElementsByClassName('1');
for (var i = 0; i < rect.length; i++) {
document.rect[i].querySelector('rect').style.fill="blue";
}
}
I'm not sure how to do the last document.rect[i].querySelector part.
rectvariable, why would you try to access it as a property ondocument?