Javascript(ES6) loop迴圈
For Loop 迴圈
var list = document.getElementsByClassName("events");
for (let item of list) {
console.log(item.id);
}
// ForEach
Array.from(document.getElementsByClassName("events")).forEach(function(item) {
console.log(item.id);
});
Class Name 新增刪除作法
document.getElementById("MyElement").classList.add('MyClass');
// 新增 Class Name 簡潔做法
document.getElementById("MyElement").className += " MyCLass"
document.getElementById("MyElement").classList.remove('MyClass');
if ( document.getElementById("MyElement").classList.contains('MyClass') )
document.getElementById("MyElement").classList.toggle('MyClass');