Is it not possible to bind the timeout to the fragment of HTML you've just generated in line 21 above?  It would feel nice to say explicitly which element to remove in this function as it would, I guess, mean that the most recently added alert would be removed when the earliest timer expires (i.e. messages received as A then B, would mean the timeout for A would remove the element for B).