Created
November 27, 2015 21:23
-
-
Save xto3na/3163263ff0226420a3fd to your computer and use it in GitHub Desktop.
Добавление - удаление классов с помощью JavaScript свойства classList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// добавление элементу класс "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