Fixed JavaScript error when element doesn't exist