You can simply do
myImage.attr("width", newWidth);
myImage.attr("height", newHeight);
where
myImage
is the DOM object corresponding to you
img
element. If you change only
width
or only
height
in both JavaScript code in and in HTML (or better yet, neither
width
nor
height
is defined in HTML), the same aspect ratio is preserved; it is defined by the "natural" dimensions of the image.
—SA