EditContext: attachedElements() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Phương thức attachedElements() của giao diện EditContext trả về một Array chỉ chứa một phần tử. Phần tử đó là phần tử được liên kết với đối tượng EditContext.

Cú pháp

js
attachedElements()

Tham số

Không có.

Giá trị trả về

Một Array chứa một đối tượng HTMLElement.

Chỉ có thể có một phần tử được liên kết với một thực thể EditContext, do đó mảng trả về sẽ luôn chứa một phần tử. Nếu API được mở rộng trong tương lai để hỗ trợ nhiều phần tử được liên kết, giá trị trả về sẽ là một mảng chứa nhiều phần tử.

Ví dụ

Lấy phần tử được liên kết với thực thể EditContext

Ví dụ này cho thấy cách dùng phương thức attachedElements để lấy phần tử được liên kết với một thực thể EditContext.

html
<canvas id="editor-canvas"></canvas>
js
const canvas = document.getElementById("editor-canvas");
const editContext = new EditContext();
canvas.editContext = editContext;

const attachedElements = editContext.attachedElements();
console.log(attachedElements[0] === canvas); // true

Thông số kỹ thuật

Specification
EditContext API
# dom-editcontext-attachedelements

Tương thích trình duyệt

Xem thêm