Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Manipulate DOM elements</title>
</head>
<body>
  <div class="something active">foo</div>
  <div class="something active">bar</div>
  <div class="something active">baz</div>
  <div class="something active">fooz</div>
  
  <button class="button">Deativate</button>
</body>
</html>
 
.something {
  background-color: #ccc;
  color: #ddd;
  width: calc(25% - 30px);
  float: left;
  padding: 10px;
  margin: 0 10px 10px 0;
}
.something.active {
  background-color: gray;
  color: white;
}
 
// var els = document.querySelectorAll('.something.active')
var els = document.getElementsByClassName('something active')
var button = document.querySelector('.button')
button.addEventListener('click', _removeClasses)
function _removeClasses() {
  els[0].classList.remove('active')
  if (els[0]) _removeClasses()
}
// function _removeClasses () {
//   while (els.length > 0) {
//      els[0].classList.remove('active')
//   }
// }
// function _removeClasses() {
//   for (var i = 0; i < els.length; i++) {
//     els[i].classList.remove('active')
//   }
// }
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x