fix $elem is not defined