Search code examples
javascriptevent-listener

Event listener for when element becomes visible?


I am building a toolbar that is going to be included into a page. the div is going to be included in will default to display: none.
Is there any way I can put an event listener on my toolbar to listen for when it becomes visible so it can initialize?
or will I have to pass it a variable from the containing page?


Solution

  • Javascript events deal with User Interaction, if your code is organised enough you should be able to call the initialising function in the same place where the visibility changes (i.e. you shouldn't change myElement.style.display on many places, instead, call a function/method that does this and anything else you might want).