3 ms·
I usually take it as suggestive code that you don’t have to use verbatim. For example, You might not need jQuery offers the following suggestions: // toggle
by divbzero 3y ago
I usually take it as suggestive code that you don’t have to use verbatim.
For example, You might not need jQuery offers the following suggestions:
// toggle visibility
function toggle(el) {
if (el.style.display == 'none') {
el.style.display = '';
} else {
el.style.display = 'none';
}
}
// remove multiple elements
for (const el of document.querySelectorAll(selector)) {
el.remove();
}
While the following would be more concise:
// toggle visibility
function toggle(el) {
el.style.display = el.style.display === 'none' ? '' : 'none;
}
// remove multiple elements
document.querySelectorAll(selector).forEach(el => el.remove());