HTML DOMTokenList xóa()
❮ Đối tượng DOMTokenListVí dụ
Xóa lớp "myStyle" khỏi một phần tử:
const list = element.classList;
list.remove("myStyle");
Hãy tự mình thử »Thêm lớp "myStyle" vào một phần tử:
const list = element.classList;
list.add("myStyle");
Hãy tự mình thử »Bật và tắt "myStyle":
const list = element.classList;
list.toggle("myStyle");
Hãy tự mình thử »Thêm ví dụ dưới đây.
Sự miêu tả
Phương thức remove()
xóa một (hoặc nhiều) mã thông báo khỏi DOMTokenList .
Xem thêm:
Cú pháp
domtokenlist .remove(token, ...)
Thông số
Parameter | Description |
token | Required. The token(s) to remove from the list. |
Giá trị trả về
KHÔNG CÓ |
Thêm ví dụ
Xóa nhiều lớp khỏi một phần tử:
element.classList.remove("myStyle", "anotherClass", "thirdClass");
Hãy tự mình thử »Xóa "anotherClass" nếu một phần tử có lớp "myStyle".
if (element.classList.contains("mystyle")) {
element.classList.remove("anotherClass");
}
Hãy tự mình thử »Hỗ trợ trình duyệt
domtokenlist.remove()
là tính năng DOM cấp 4 (2015).
Nó được hỗ trợ trong tất cả các trình duyệt hiện đại:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
domtokenlist.remove()
không được hỗ trợ trong Internet Explorer 11 (hoặc phiên bản cũ hơn).
❮ Đối tượng DOMTokenList