I have a 'div' that I 'fadeOut' after pressing a button using javascript. After the 'div' has faded out I would like it to 'fadeIn'. This is presently not happening for me. I understand the concept of the callback function but I appear not to have succeeded in implementing it in my code. Please can someone advise? I would like a callback function solution if that is possible.
function fade_effect(element, callback) {
var x = function(element) {
var elem = document.getElementById(element);
elem.style.transition = "opacity 2.0s linear 0s";
elem.style.opacity = 0;
return elem;
}
var thisElement = x(element);
fadeIn(thisElement);
}
function fadeIn(element_input) {
element_input.style.transition = "opacity 2.0s linear 0s";
element_input.style.opacity = 1;
}
div#box1 {
background: #9dceff;
width: 400px;
height: 200px;
}
<button onclick="fade_effect('box1',fadeIn);">Magenta</button>
<div id="box1">Content in box 1 ...</div>