A finite element approach for the immersed boundary method