HTMLImageElement: name property

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Thuộc tính deprecated name của giao diện HTMLImageElement chỉ định tên cho phần tử. Nó phản ánh thuộc tính nội dung name của phần tử <img>. Nó đã được thay thế bằng thuộc tính id có sẵn trên tất cả các thành phần và chỉ được giữ lại vì lý do tương thích.

Giá trị

Một chuỗi cung cấp tên mà hình ảnh có thể được tham chiếu.

Ví dụ

Đặt thuộc tính tên

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

Thay vì làm điều này, hãy đặt thuộc tính id:

js
img.id = "example-img";

Thông số kỹ thuật

Specification
HTML
# dom-img-name

Khả năng tương thích của trình duyệt