Note that attachEvent is no longer supported in IE11 and you should use addEventListner that can be used to bind specific function to an event.
In older versions of IE, you can use like this:
A String that specifies any of the standard DHTML Events.
The Pointer that specifies the function to call when the event fires.
Boolean returns any of the below value:
Return value Description
True The function was bound successfully to the event.
False The function was not bound to the event.
Note that IE has included support for addEventListener from IE9 and above only. Now if you want to support IE8, I would suggest you to use some cross-browser library like jQuery to bind event handlers.
For more information about addEventListener, refer below Microsoft site link: