The call to getAttribute fails if the image is not a jquery object, changed in favor of $.attr