I have a bunch of js code that I'm trying to wrap using the module pattern:
(function(){
function closeClicked(closeButton)
{
//do some stuff
}
//some more js code
}());
The html caller is defined like this:
<button type="button" onclick="closeClicked(this)">
<span aria-hidden="true">×</span></button>
The code injects some html into an element on the page and the button within the html calls the js function. This works as expected but the function is not found when all of the code is wrapped as a module. Do I need to define or call the function differently when this code is wrapped as a module?
closeClickedoutside the anonymous function. There are two options: either add an event listener in JavaScript, not in HTML or exposecloseClickedin global scope (I do not advice doing that).