25.12. The Image Object

The Image object corresponds to HTML elements inserted through <IMG SRC="..." ...>. An Image object is accessed through the document.images array or, if the image is named, through document.imageName. Manipulating images through JavaScript is an important capability; see Section 24.5 (Using JavaScript to Make Pages Dynamic) for examples.

Constructor

new Image(width, height) This constructor allocates a new Image object of the specified size. The main purpose for an Image object is to then set its src property in order to preload images that are used later. In such an application, the Image object is never actually used after its src is set; the purpose is to get the browser to cache the image. See Section 24.5 (Using JavaScript ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.