Cette traduction est incomplète. Aidez à traduire cet article depuis l'anglais.
HTML image element interface
DOM image objects expose the HTMLImageElement (or HTML 4 HTMLImageElement) interface, which provides special properties and methods (beyond the regular element object interface they also have available to them by inheritance) for manipulating the layout and presentation of input elements.
Propriétés
| Nom | Type | Description |
|---|---|---|
align Obsolète depuis HTML4 Obsolète depuis HTML5 |
DOMString |
Indicates the alignment of the image with respect to the surrounding context. |
alt |
DOMString |
L'atribut alt indique le texte alternatif qui sera affiché si l'image ne peut être chargée. |
border Obsolète depuis HTML4 Obsolète depuis HTML5 |
DOMString |
Width of the border around the image. |
complete HTML5 |
readonly Boolean |
True if the browser has fetched the image, and it is in a supported image type that was decoded without errors. |
crossOrigin HTML5 |
DOMString |
The CORS setting for this image element. See CORS settings attributes for details. |
height |
DOMString |
L'atribut height permet d'indiquer la hauteur de l'image en pixels CSS. |
hspace Obsolète depuis HTML4 Obsolète depuis HTML5 |
long |
Space to the left and right of the image. |
isMap |
Boolean |
Reflects the ismap HTML attribute, indicating that the image is part of a server-side image map. |
longDesc Obsolète depuis HTML5 |
DOMString |
URI of a long description of the image. |
naturalHeight HTML5 only |
readonly unsigned long | Intrinsic height of the image in CSS pixels, if it is available; otherwise, 0. |
naturalWidth HTML5 only |
readonly unsigned long | Intrinsic width of the image in CSS pixels, if it is available; otherwise, 0. |
src |
DOMString |
L'atribut src indique l'URL source de l'image. |
| srcset | DOMString |
L'atribut srcset permet d'indiquer plusieurs URL d'image en fonction de la résolution et de la taille de l'ecran de l'utilisateur. |
useMap |
DOMString |
Reflects the usemap HTML attribute, containing a partial URL of a map element. |
vspace Obsolète depuis HTML4 Obsolète depuis HTML5 |
long |
Space above and below the image. |
width |
DOMString |
L'atribut width permet d'indiquer la largeur de l'image en pixels CSS. |
Other properties (Gecko)
-
lowsrc - A reference to a low-quality (but faster to load) copy of the image.
-
x - Read only long, like Netscape 4.
-
y - Read only long, like Netscape 4.
Note: The
x and y properties were removed in Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4) but restored in Gecko 14.0 (Firefox 14.0 / Thunderbird 14.0 / SeaMonkey 2.11) for compatibility reasons.Exemple
var img1 = new Image(); // DOM 0
img1.src = 'image1.png';
img1.alt = 'alt';
document.body.appendChild(img1);
var img2 = document.createElement('img'); // use DOM HTMLImageElement
img2.src = 'image2.jpg';
img2.alt = 'alt text';
document.body.appendChild(img2);
// using first image in the document
alert(document.images[0].src);