declare $elem as local var

The variable $elem isn't declared in plugin scope so it gets global. This can lead to problems if the plugin gets used in a strict environment.