Removed direct DOM access and used $elem in place