Add a class:
w3.addClass(
selector,'
class')
Add multiple classes:
w3.addClass(
selector,'
class1
class2
class3...')
Add the "marked" class to an element with id="London":
<button onclick="w3.addClass('#London','marked')">Add Class</button>
Add the "marked" class to all <h2> elements:
<button onclick="w3.addClass('h2','marked')">Add Class</button>
Add the "marked" class to an elements with class="city":
<button onclick="w3.addClass('.city','marked')">Add Class</button>
To add multiple classes to an element, separate each class with a space.
Add both "class1" and "class2" to an element with id="London":
<button onclick="w3.addClass('#London','class1 class2')">Add Classes</button>
Remove a class:
w3.removeClass(
selector,'
class')
Remove multiple classes:
w3.removeClass(
selector,'
class1
class2
class3...')
Remove the "marked" class from an element with id="London":
<button onclick="w3.removeClass('#London','marked')">Remove Class</button>
Remove the "marked" class from all <h2> elements:
<button onclick="w3.removeClass('h2','marked')">Remove Class</button>
Remove the "marked" class from all elements with class="city":
<button onclick="w3.removeClass('.city','marked')">Remove Class</button>
To remove multiple classes from an element, separate each class with a space.
Remove both "class1" and "class2" from an element with id="London":
<button onclick="w3.removeClass('#London','class1 class2')">Remove Classes</button>
Toggle a class (on/off):
w3.toggleClass(
selector,'
class')
Toggle between two classes:
w3.toggleClass(
selector,'
property','
class','
class')
Toggle between the "marked" class of an element with id="London":
<button onclick="w3.toggleClass('#London','marked')">Toggle</button>
Toggle between the "marked" class of all <h2> elements:
<button onclick="w3.toggleClass('h2','marked')">Toggle</button>
Toggle between the "marked" class of all elements with class="city":
<button onclick="w3.toggleClass('.city','marked')">Toggle</button>
Toggle between the class name "class1" and "class2" of id="London:
<button onclick="w3.toggleClass('#London','class1','class2')">Toggle</button>