changed DOM logic to jquery