<svg xmlns="http://www.w3.org/2000/svg" id="root" width="100" height="100" viewBox="0 0 100 100"> <rect id="r" width="100" height="100" fill="green"> <set attributeName="fill" to="red"/> </rect> <script>document.getElementById("r").setAttribute("fill", "red");</script> </svg>