Change height and width of SVG object using JavaScript

38,066

In SVG width and height of <rect> elements are attributes and not CSS properties so you'd need to write

document.getElementById('cercle1').setAttribute("height", "10px");

similarly for the width.

Share:
38,066
akm
Author by

akm

Updated on September 13, 2020

Comments

  • akm
    akm over 3 years

    I want to change height and width of an svg object on a button click. I tried it but it doesn't work:

    function modify() {
        document.getElementById('circle1').style.height = "10px";
        document.getElementById('circle1').style.width = "10px";        
    }