I am trying to do something pretty simple in vanilla JS in order to practice closures. It goes like this, user input is cached and returned/displayed to another element.
This works good, but I want to run a callback function to change the background color of the target, and I just cannot get it to run, I have had it right at one point, including making the callback optional and checking if the callback argument is a function, but then i played around some more and cannot replicate the working code anymore.
This is the function:
<code>
var link = document.getElementById(“link”);
var getNames = document.getElementById(“getName”);
var lastName = getNames.value;
function showName (lastName, callback) {
var nameIntro = “Your name is “;
function makeFullName () {
return nameIntro + ” ” + lastName;
}
return makeFullName ();
}
link.addEventListener(‘click’,(function(callback){
link.insertAdjacentHTML(‘beforeend’, showName (getNames.value ));
callback();
})
)
</code>
And this is the codepen link
A Pen by damiano
I know this may be an odd question, but can you pass 2 callback functions as arguments at once, and if so, how do it?