JSFiddle - React, Tailwind, and code Playground
by Hans PUFAL
HTML
<h1>Value 1</h1>
<h1>Value 2</h1>
<h1>value 3</h1>
JavaScript
function forContent (selector, content, action) {
[].forEach.call (document.querySelectorAll (selector), function (h) {
(content === null || // null value means action ALL ooccurences
typeof content == 'function' && content (h.innerHTML) || // call function
typeof content == 'string' && content == h.innerHTML || // Compare with string
content.test && content.test (h.innerHTML)) && // test with RegExp
action (h);
});
}
(function cycle () {
window.setTimeout (function () {
forContent ('h1', 'Value 2', function (el) {
el.style.display = 'none';
});
}, 1000);
window.setTimeout (function () {
forContent ('h1', /Value */i, function (el) {
el.style.display = 'none';
});
}, 2000);
window.setTimeout (function () {
forContent ('h1', null, function (el) {
el.style.display = '';
});
}, 3000);
window.setTimeout (cycle, 5000);
}) ()