changed js code by creating one loop for all searching elements