Reputation: 23999
I have a function which I hold in a master .js
file:
$(document).on('click', '.closeicon', function closeNotif(duration) {
doSomething
}
I have a link with class closeicon
which when clicked fires the function, no problem.
How though can I close it manually from within another function in the same master file?
I'm trying:
function doSomethingElse (){
closeNotif(duration)
}
But I get the error closeNotif is not defined
Upvotes: 1
Views: 48
Reputation: 944064
Because of the context you have put the function
keyword in, you have created a named function expression, not a declaration.
Consequently, it doesn't generate a variable of the same name.
Use a function declaration instead. Then pass that to on
.
function closeNotif(event) {
doSomething
}
$(document).on('click', '.closeicon', closeNotif)
Upvotes: 2