Phương thức jQuery removeClass ()

❮ Phương thức HTML / CSS jQuery

Thí dụ

Xóa tên lớp "giới thiệu" khỏi tất cả các phần tử <p>:

$("button").click(function(){
  $("p").removeClass("intro");
});

Định nghĩa và Cách sử dụng

Phương thức removeClass () xóa một hoặc nhiều tên lớp khỏi các phần tử đã chọn.

Lưu ý: Nếu không có tham số nào được chỉ định, phương thức này sẽ xóa TẤT CẢ tên lớp khỏi các phần tử đã chọn.


Cú pháp

$(selector).removeClass(classname,function(index,currentclass))

Parameter Description
classname Optional. Specifies one or more class names to remove. To remove several classes, separate the class names with space

Note: If this parameter is empty, all class names will be removed
function(index,currentclass) Optional. A function that returns one or more class names to remove
  • index - Returns the index position of the element in the set
  • currentclass - Returns the current class name of selected elements

Hãy tự mình thử - Ví dụ


Cách sử dụng addClass () và removeClass () để xóa một tên lớp và thêm một tên lớp mới.


Sử dụng hàm để xóa lớp khỏi các phần tử đã chọn.


Cách xóa một số tên lớp khỏi các phần tử đã chọn.


❮ Phương thức HTML / CSS jQuery