I'm trying to create a similar function to the jquery .fadeOut()
effect in pure javascript, but I'm having trouble with my code. The error code:
span[0].fadeOutEffect is not a function
My code:
var span = document.querySelectorAll("span");
function fadeOutEffect() {
var node = this
var fadeEffect = setInterval(function() {
if (!node.style.opacity) {
node.style.opacity = 1;
}
if (node.style.opacity > 0) {
node.style.opacity -= 0.1;
} else {
clearInterval(fadeEffect);
}
}, 50);
}
span[0].fadeOutEffect();
<span>one </span><span>two </span><span>three </span>