JSFiddle - React, Tailwind, and code Playground

by petroveg

HTML

<div class="start"></div>

JavaScript

var style = document.createElement('style'),
	link;

style.type = 'text/css';
document.head.appendChild(style);
link = document.styleSheets[document.styleSheets.length - 1];
link.insertRule('.start{width:300px;height:200px;background:#69c;}', link.cssRules.length);
link.insertRule('.test{background:#f60;}', link.cssRules.length);

document.addEventListener('click', function (e) {
	var target = e.target;

	while (target && !/\bstart\b/.test(target.className)) {
		target = target.parentNode;
	}

	if (target) {
		if (/\btest\b/.test(target.className)) {
			target.className = target.className.replace(/\s*\btest\b/g, '');
		} else {
			target.className += ' test';
		}
	}
}, false);