CSSPseudoElement
Khả dụng hạn chế
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.
Giao diện CSSPseudoElement biểu thị một pseudo-element có thể là mục tiêu của một sự kiện hoặc được tạo hoạt ảnh bằng Web Animations API. Các phiên bản của giao diện này có thể thu được bằng cách gọi Element.pseudo().
Thuộc tính phiên bản
CSSPseudoElement.elementThử nghiệm Read only-
Trả về
Elementgốc/cha của pseudo-element. CSSPseudoElement.typeThử nghiệm Read only-
Trả về bộ chọn pseudo-element dưới dạng chuỗi.
Phương thức phiên bản
CSSPseudoElement mở rộng EventTarget, vì vậy nó kế thừa các phương thức sau:
Ví dụ
>Ví dụ cơ bản sử dụng Element.pseudo
Sử dụng pseudo-elements, hầu hết các trình duyệt hiện đại sẽ tự động thêm dấu ngoặc kép xung quanh văn bản trong phần tử <q>. (Có thể cần một quy tắc style để thêm dấu ngoặc kép trong các trình duyệt cũ hơn.) Ví dụ dưới đây minh họa các thuộc tính cơ bản của đối tượng CSSPseudoElement biểu thị dấu ngoặc kép mở.
const element = document.querySelector("q");
const cssPseudoElement = element.pseudo("::before");
console.log(cssPseudoElement.element); // Outputs [object HTMLQuoteElement]
console.log(cssPseudoElement.type); // Outputs '::before'
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| CSS Pseudo-Elements Module Level 4> # CSSPseudoElement-interface> |