0
点赞
收藏
分享

微信扫一扫

隐藏所有指定的元素

素的盐 2022-07-27 阅读 164

使用展开运算符(​​...​​​)和 ​​Array.prototype.forEach()​​​ 将 ​​display: none​​ 应用于指定的每个元素。

const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'))

// 隐藏页面上的所有 <img> 元素
hide(...document.querySelectorAll('img'))

举报

相关推荐

0 条评论