HTMLImageElement: name property - Web APIs | MDN

Value

A string providing a name by which the image can be referenced.

Examples

Setting the name attribute

js

const img = new Image();
img.src = "example.png";
img.alt = "An example picture";
img.name = "example-img";

Instead of doing this, set the id property instead:

js

img.id = "example-img";

Specifications

Specification
HTML
# dom-img-name

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.