Metoda jQuery removeClass()

❮ Metody jQuery HTML/CSS

Przykład

Usuń nazwę klasy „intro” ze wszystkich elementów <p>:

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

Definicja i użycie

Metoda removeClass() usuwa jedną lub więcej nazw klas z wybranych elementów.

Uwaga: Jeśli nie zostanie określony żaden parametr, ta metoda usunie WSZYSTKIE nazwy klas z wybranych elementów.


Składnia

$(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

Spróbuj sam - przykłady


Jak używać addClass() i removeClass() w celu usunięcia jednej nazwy klasy i dodania nowej nazwy klasy.


Użycie funkcji do usunięcia klasy z wybranych elementów.


Jak usunąć kilka nazw klas z wybranych elementów.


❮ Metody jQuery HTML/CSS