CSSRuleList: phương thức item()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Phương thức item() của giao diện CSSRuleList trả về đối tượng CSSRule tại index được chỉ định hoặc null nếu index được chỉ định không tồn tại.

Cú pháp

js
item(index)

Tham số

index

Một số nguyên.

Giá trị trả về

Một CSSRule.

Ví dụ

Trong ví dụ sau, chúng ta giả định rằng danh sách myRules chỉ có ba mục.

js
let myRules = document.styleSheets[0].cssRules;
console.log(myRules.item(0)); // Logs the first CSSRule item from this list

// Accessing non-existing items using this method will return null instead of undefined
console.log(myRules.item(5)); // null
console.log(myRules[5]); // undefined

Thông số kỹ thuật

Thông số kỹ thuật
CSS Object Model (CSSOM)
# dom-cssrulelist-item

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