Problem with setting element - events not being attached