Reputation: 11
I'm trying to make a function that whenever I click on the button, the image on the screen width decrease by 100px, the width of the picture are all 800px here is what I have:
var width_of_pic = 800 ;
function shrink() {
width_of_pic = width_of_pic - 100;
var image_element= document.getElementById( "image_element_id" ) ;
image_element.style.width = width_of_pic;
}
Upvotes: 0
Views: 54
Reputation: 208002
Assuming that the ID is correct, you need to specify a unit:
image_element.style.width = width_of_pic+'px';
Upvotes: 4