I want to display some key values from objects on click. Each button has a click listener calling the prototypes method for various instances of employee.
This works ok-ish.
But i want the output method to do the following when a button is clicked: - opacity:0, then slide the height of #demo to 1px(just very small), and then when the new innerHTML value is in #demo, to animate the height back to 30px and opacity to 0. I have tried to pass the callback functions in many ways, always getting type error. The next issue is how the set the this context properly when working with addEventListener and is it somehow possible to get around assigning a different function to each eventListener?
function employee(name, jobtitle, born) {
this.name=name;
this.jobtitle=jobtitle;
this.born=born;
this.callback = function(){};
}
employee.prototype.output = function(){
var pee = document.querySelector("p");
pee.style.opacity = 0;
pee.style.height = "30px";
pee.style.opacity = 1;
return this.name + "is a " + this.jobtitle + " born in the year" + this.born};
Link to the codepen:
http://codepen.io/damianocel/pen/MeaeGX
Javascript only please, I can get this in Jquery, but there is still some learning to do for how this happens in vanilla JS.