Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xto3na/3163263ff0226420a3fd to your computer and use it in GitHub Desktop.
Save xto3na/3163263ff0226420a3fd to your computer and use it in GitHub Desktop.
Добавление - удаление классов с помощью JavaScript свойства classList
// добавление элементу класс "foo"
el.classList.add("foo");
// удаление класса "bar"
el.classList.remove("bar");
// переключение класса "foo"
el.classList.toggle("foo");
// возвращает "true" если у класса есть класс "foo", в противном случае "false"
console.log( el.classList.contains("foo") );
// добавление нескольких классов
el.classList.add( "foo", "bar" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment