close
classList.add 新增class
element.classList.add('some-class');
classList.remove 移除class
element.classList.remove('some-other-class');
classList.toggle 切換class
element.classList.toggle('toggle-class');
classList.contains 檢查class
if(element.classList.contains('some-class')){
console.log('yes!');
}
classList只有支援到IE10,不過有polyfill可支援到IE8+
REFERENCE: go make thing
文章標籤
全站熱搜
留言列表