Pass event to the function:
click here
function fun(event, userID)
{
event= event|| window.event;
var btn = event.target;
alert(btn.id);
}
OR
Make sure your event is not undefined
function fun(userID)
{
var e = event || window.event;
var btn = e.target;
alert(btn.id);
}