akm
akm

Reputation: 465

Change height and width of SVG object using JavaScript

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";        
}

Upvotes: 29

Views: 48109

Answers (1)

Robert Longson
Robert Longson

Reputation: 123985

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.

Upvotes: 62

Related Questions