Here, hopefully, a sample code is enough to give you what you want:
var myImage = document.getElementById("myImagesId"); var imageWidth = myImage.offsetWidth; var imageHeight = myImage.offsetHeight;
This should give you the numbers you need to get the solution you need. I think you yourself can write the rest of the code. :)
EDIT: I couldn't help myself here - is that what you need?
function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName("img"); for(var i = 0; i < images.length;i++) { if(images[i].offsetWidth > width) { images[i].style.width= (width + "px"); } } }
source share