function
setup() {
createCanvas(600, 300);
textSize(18);
tmpElement = createElement(
"div"
);
text(
"Click on the buttons to add, remove "
+
"or check the class of the element"
, 20, 20);
setBtn =
createButton(
"Add color class to element"
);
setBtn.position(30, 40);
setBtn.mouseClicked(() => {
tmpElement.addClass(
"color"
);
});
removeBtn =
createButton(
"Remove color class from element"
);
removeBtn.position(30, 80);
removeBtn.mouseClicked(() => {
tmpElement.removeClass(
"color"
);
});
showBtn = createButton(
"Check if class exists"
);
showBtn.position(30, 120);
showBtn.mouseClicked(checkClass);
}
function
checkClass() {
clear();
let hasC = tmpElement.hasClass(
"color"
);
text(
"hasClass('color') gives the output: "
+
hasC, 20, 180);
text(
"Click on the buttons to add, remove or "
+
"check the class of the element"
, 20, 20);
}