Click Events

Pure JavaScript

by dixalex

HTML

<span id='theTarget'>Click Me</span>

JavaScript

//https://css-tricks.com/forums/topic/addclass-with-pure-javascript/

var isDown = "isDown";
var isUp = isDown + ' ' + 'isUp';
var targetElement = document.getElementById("theTarget");
var imgScanner = setInterval(function() {
  if (targetElement.innerHTML === "Click Me") {
    targetElement.addEventListener("mousedown", mD);
    targetElement.addEventListener("mouseup", mU);
    //document.getElementById("theTarget").className = "isDown";
    if (targetElement.style.color === "blue") {
      targetElement.style.color = "black";
    }
    //clearInterval(imgScanner);
  } else {
    var doNothing = "";
  }
}, 50);

function mD() {
  targetElement.style.color = "red";
  targetElement.className = isDown;
}


function mU() {
  targetElement.style.color = "blue";
  targetElement.className = isUp;
}

console.log(targetElement.innerHTML);