by divbzero · 2y ago · 0 comments
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());