updated javascript to require element to exist