Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JS classList

-- HTML --
<div class='container'></div>

-- JAVASCRIPT --
element.classList.contains('container'); // True or false
element.classList.add('my-class'); // Adds the class if it isn't present yet
element.classList.remove('my-class'); // Removes the class if it’s present
element.classList.toggle('my-class'); // Adds if not present, else removes
Source by careerfoundry.com #
 
PREVIOUS NEXT
Tagged: #JS #classList
ADD COMMENT
Topic
Name
7+8 =