reworking on location hierarchy javascript