insertBefore should be on link.parentNode instead of just link.